Skip to main content

Oneenv-based settings management and fast logging library

Project description

OneLogger 🚀

A Simple and Efficient Logging Library

OneLogger is a lightweight logging library built to help you dynamically configure and manage log settings with ease using oneenv. It leverages Python's built-in logging module and (for Python versions up to 3.12) enhances performance with picologging. Perfect for development, testing, and production environments!

Features ✨

  • Dynamic Configuration: Easily manage logging settings using environment variables via oneenv.
  • High Performance Logging:
    • For Python versions ≤ 3.12, OneLogger uses picologging to deliver blazing-fast logging 🚀.
    • For Python 3.13 and later, it seamlessly falls back to the standard logging module.
  • Flexible Output Options: Configure logs to output to the console, files (with rotation), or both.
  • Custom Formatting: Supports both plain text and JSON log formats.
  • Asynchronous Logging: Optionally enable asynchronous logging for better performance under high load.
  • Easy Integration: A simple API with a singleton pattern for effortless logger retrieval.

Supported Environments 🖥️

  • Python ≥ 3.11
    • Python < 3.13: Utilizes picologging for enhanced performance.
    • Python ≥ 3.13: Uses the standard logging module for full compatibility.

Installation 🛠️

For Users 👥

pip install onelogger

For Developers 🛠️

  1. Clone the Repository

    git clone <repository-url>
    cd onelogger
    
  2. Create and Activate a Virtual Environment

    python -m venv .venv
    # Windows (PowerShell)
    .\.venv\Scripts\Activate.ps1
    # macOS/Linux
    source .venv/bin/activate
    
  3. Install Development Dependencies

    pip install -e ".[dev]"
    

Usage 🚀

OneLogger integrates effortlessly into your projects. For example:

from onelogger import Logger

# Retrieve a configured logger instance
logger = Logger.get_logger("example_logger")

# Log messages at various levels
logger.info("This is an informational message.")
logger.error("This is an error message.")

try:
    result = 1 / 0
except Exception as e:
    logger.exception("An exception occurred during division!")

You can try out the example provided in the examples folder:

python examples/example_logger.py

Configuration 📦

OneLogger uses oneenv to manage environment variables with ease. The library automatically generates a .env.example template file with detailed descriptions for all available settings. This makes it simple to:

  • View all available configuration options with descriptions
  • Understand the purpose and valid values for each setting
  • Create your own .env file by copying and modifying the template

Here's an example of the auto-generated template:

# Auto-generated by OneEnv

# Specifies the logging level used by OneLogger.
# Valid options are DEBUG, INFO, WARNING, ERROR, and CRITICAL.
# Required
LOG_LEVEL=DEBUG

# Specifies the destination for log output.
# Options: 'console' for standard output, 'file' for file logging, or 'both'.
# Required
LOG_OUTPUT=both

# Specifies the log file path when LOG_OUTPUT is set to 'file' or 'both'.
LOG_FILE_PATH=example.log

# ... (other settings with descriptions)

To configure OneLogger, simply:

  1. Copy .env.example to .env
  2. Modify the values in .env according to your needs
  3. OneLogger will automatically load these settings when initialized

Contributing 🤝

Contributions are welcome! Please follow best practices and add tests as necessary.

License 📄

This project is licensed under the MIT License.

Color Support 🎨

OneLogger supports ANSI color codes in log messages:

  • Console output shows colored messages (when supported)
  • File output can strip color codes (configurable via LOG_STRIP_COLORS)

Windows Users

Color support is automatically enabled on Windows 10 and later. For earlier versions, you might need to use Windows Terminal or another terminal that supports ANSI colors.

Environment Variables

  • LOG_STRIP_COLORS: Set to "true" to remove color codes from file output (default: "false")
  • NO_COLOR: Set to any value to disable colors completely

Enjoy fast and configurable logging with OneLogger! 🎉

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

onelogger-0.1.2.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

onelogger-0.1.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file onelogger-0.1.2.tar.gz.

File metadata

  • Download URL: onelogger-0.1.2.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for onelogger-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b2492b829fe53c9e66bd4ee3782956cc0b180ca7703a8eedc51c9501f025b7c6
MD5 1cc87cf7262c3d95c780b6f22c1c68b0
BLAKE2b-256 11944c7a081dbfde0747d9dceb14320fb519c7adb007d349a768cee682b38100

See more details on using hashes here.

File details

Details for the file onelogger-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: onelogger-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for onelogger-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d2cd9ac071e538b0fc07e8ef409bcf6b284ed7619c939b53e5492e8b7c687ec1
MD5 cb2533cc29e1f614e3c9f47a2ace57f4
BLAKE2b-256 23380e9500d69be6837cb6fd3eeb853301cf3d25023b9c04658c08e98916683f

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