A customizable logger and traceback handler for Python applications
Project description
FlexiLogger
FlexiLogger is a customizable Python logging library that provides enhanced features for handling logs, including colorized console outputs, log file formatting, and detailed traceback management.
Features
- Colorized console logging for better readability.
- File-based logging with customizable formats.
- Dynamic configuration via environment variables.
- Enhanced traceback extraction and logging.
- Customizable log level spaces for better alignment.
Installation
You can install FlexiLogger using pip:
pip install FlexiLogger
Usage
Basic Usage
To use FlexiLogger in your project:
from FlexiLogger import Logger
logger = Logger(__file__, log_file_path="app.log")
logger.info("This is an info message")
logger.error("This is an error message")
Advanced Traceback Handling
FlexiLogger provides a GetTraceback class for managing exceptions:
from FlexiLogger import GetTraceback
try:
1 / 0
except Exception as e:
traceback_handler = GetTraceback(__file__)
traceback_handler.error("An error occurred", print_full_exception=True)
Environment Variables
FlexiLogger uses several environment variables to customize its behavior:
| Variable Name | Description | Default Value |
|---|---|---|
LOG_PATH |
Specifies the path to the log file. If not set, logging to a file is disabled. | None |
LOGGER_CONSOLE_LOG_LEVEL |
Sets the console log level. Acceptable values: DEBUG, INFO, WARNING, ERROR, CRITICAL. |
DEBUG |
LOGGER_FILE_LOG_LEVEL |
Sets the file log level. Acceptable values: DEBUG, INFO, WARNING, ERROR, CRITICAL. |
DEBUG |
LOGGER_TIME_INFO |
Enables or disables timestamps in log messages. Values: true/1 or false/0. |
true |
Example
Set the environment variables before running your script:
export LOG_PATH="app.log"
export LOGGER_CONSOLE_LOG_LEVEL="INFO"
export LOGGER_FILE_LOG_LEVEL="ERROR"
export LOGGER_TIME_INFO="false"
Project Structure
FlexiLogger/
├── __init__.py
├── logger.py
├── gettraceback.py
├── README.md
License
FlexiLogger is licensed under the MIT License. See the LICENSE file for details.
Contributions
Contributions are welcome! Feel free to open an issue or submit a pull request.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flexilogger-1.0.0.tar.gz.
File metadata
- Download URL: flexilogger-1.0.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de5fb8ebe8d305de78375f69d159a5a43701cb31aaa94dbfb257a4823835431e
|
|
| MD5 |
7982d478e85bede826f73c57e7adddc8
|
|
| BLAKE2b-256 |
a98f803445b8bd0f8b7599b7ef41258d757a65f8288ed466bc78a6f1073fe9b0
|
File details
Details for the file FlexiLogger-1.0.0-py3-none-any.whl.
File metadata
- Download URL: FlexiLogger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b51b3c8c65ee8aa5350802ade3ff87d5871df08973542d7df02eb927fe4e01
|
|
| MD5 |
b9548bd6300977d22e35b1c12a065f8c
|
|
| BLAKE2b-256 |
d5c1e2f58d8808ee2d45fa36c3867f2688bd52481bbf47cb591b2b18a7a52458
|