|
1 | 1 | # FusionLogger-Python
|
2 |
| -FusionLogger-Python |
| 2 | + |
| 3 | +FusionLogger-Python is a centralized logging framework that provides configurable log levels and dynamic scopes for fine-grained control over application logging. It features structured log records, flexible template-based formatting via tokens, and a fluent builder for easy logger configuration. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Configurable Log Levels:** Supports `DEBUG`, `INFO`, `WARNING`, and `CRITICAL` levels. |
| 8 | +- **Dynamic Scopes:** Easily set and clear logging scopes for contextual logging. |
| 9 | +- **Flexible Formatting:** Customizable output format via token-based formatting; define log formats and datetime formats through string parameters in the formatter constructor. |
| 10 | +- **Dual Logging Outputs:** Supports both console and file logging (file mode: append). |
| 11 | +- **High Performance:** Capable of processing approximately 3000 log messages per second. |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +- **Python Versions:** |
| 16 | + - Developed under Python 3.12 |
| 17 | + - Linted with PyLint under Python 3.8, 3.9, and 3.10 |
| 18 | +- **External Dependencies:** None |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +Install FusionLogger-Python via pip: |
| 23 | + |
| 24 | +```bash |
| 25 | +pip install fusion_logger_lasse27 |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +A simple usage example can be found in the provided `TestBenchmark.py` file. Here is a brief example of how to initialize and use the logger: |
| 31 | + |
| 32 | +```python |
| 33 | +from fusion_logger import FusionLoggerBuilder, FusionLogLevel |
| 34 | + |
| 35 | +# Build and configure the logger |
| 36 | +logger = FusionLoggerBuilder() \ |
| 37 | + .set_name("MyAppLogger") \ |
| 38 | + .set_min_level(FusionLogLevel.DEBUG) \ |
| 39 | + .write_to_file("app.log") \ |
| 40 | + .build() |
| 41 | + |
| 42 | +# Log messages at different levels |
| 43 | +logger.debug("This is a debug message.") |
| 44 | +logger.info("This is an info message.") |
| 45 | +logger.warning("This is a warning message.") |
| 46 | +logger.critical("This is a critical error message.") |
| 47 | +``` |
| 48 | + |
| 49 | +## Configuration |
| 50 | + |
| 51 | +- **Logging Levels:** |
| 52 | + Set the minimum output level (e.g., DEBUG, INFO, WARNING, CRITICAL) using the fluent builder. |
| 53 | + |
| 54 | +- **Output Formats:** |
| 55 | + Specify custom log output formats by passing a format string to the `FusionLogFormatter` constructor. |
| 56 | + Additionally, provide a custom datetime format string (using `datetime.strftime()` formatting) if desired. |
| 57 | + |
| 58 | +- **File Logging:** |
| 59 | + The logger writes log entries to files in append mode. Simply add file paths via the builder methods. |
| 60 | + |
| 61 | +## Provided Components |
| 62 | + |
| 63 | +- **FusionLogger:** Core logging class handling log message creation and processing. |
| 64 | +- **FusionLoggerBuilder:** Fluent builder for easy and chainable logger configuration. |
| 65 | +- **FusionLogProcessor:** Singleton-based processor for handling log records (work in progress for thread safety). |
| 66 | +- **FusionLogFormatter:** Component to format log records based on templates. |
| 67 | +- **FusionLogRecord:** Structured container for all log entry metadata. |
| 68 | +- **FusionLogLevel:** Enum defining available log severity levels. |
| 69 | + |
| 70 | +## Performance & Best Practices |
| 71 | + |
| 72 | +For best performance, initialize the logger during application startup. The token-based formatting approach is optimized for high throughput, achieving roughly 3000 messages per second. Note that while the processor's singleton implementation is designed for thread-safe operations, full thread safety is still a work in progress. |
| 73 | + |
| 74 | +## Known Issues |
| 75 | + |
| 76 | +- There are currently no known bugs. |
| 77 | + |
| 78 | +## License |
| 79 | + |
| 80 | +This project is licensed under the [MIT License](LICENSE). |
| 81 | + |
| 82 | +## Additional Information |
| 83 | + |
| 84 | +For further details, please refer to the `pyproject.toml` file which contains project metadata and hosting information (e.g., GitHub repository details). |
0 commit comments