Skip to main content

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:

import os

os.environ['LOG_PATH'] = 'app.log'  # noqa
from FlexiLogger import Logger, GetTraceback

logger = Logger(__file__, log_file_open_format='w')
traceback_handler = GetTraceback(logger)

try:
    1 / 0
except Exception as e:
    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
LOG_TRACEBACK_PATH Specifies the path where traceback will be saved. If not set, the file defined in the Logger will be used. 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/
├── src/
│   └── FlexiLogger/
│       ├── __init__.py
│       ├── gettraceback.py
│       ├── logger.py
│       └── py.typed
├── .pre-commit-config.yaml
├── CONTRIBUTING.md
├── LICENSE
├── pyproject.toml
└── README.md

License

FlexiLogger is licensed under the MIT License. See the LICENSE file for details.


Contributions

Contributions are welcome! Please read our Contributing Guide to learn how to set up your environment and submit your changes.

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

flexilogger-1.0.4.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexilogger-1.0.4-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file flexilogger-1.0.4.tar.gz.

File metadata

  • Download URL: flexilogger-1.0.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for flexilogger-1.0.4.tar.gz
Algorithm Hash digest
SHA256 95dc987fc8cbf27315416f1654e8ca8467ad534b8992ce3fefab4ea14fbc0613
MD5 2003d30a9c8e2b587bc96da36924989e
BLAKE2b-256 9cef5bcea1b084e4a8f88ba77d058f0aa5655d5a6f2f775e8825142b596adfb5

See more details on using hashes here.

File details

Details for the file flexilogger-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: flexilogger-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for flexilogger-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f9b55b411f3831f88bf407024edcaee818c312f1befa54c21b38d3920ef41f76
MD5 4782206db5677f0e27fc5de83c115713
BLAKE2b-256 48b3a9870a1152862b7acc5f383aecbbe7ac0f233bb1369f27302bcc19f86523

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page