Skip to main content

A module to handle in a standard way for all my cli python scripts.

Project description

RincewindLogger

A flexible logging module designed for Python applications, RincewindLogger offers enhanced logging functionalities with support for file rotation based on file size, customizable logging levels, and optional console output. It facilitates easy setup for effective logging management with rotation and retention policies tailored for both development and production environments.

Features

  • File Size Rotation: Automatically rotates log files upon reaching a specified size limit to manage logs efficiently.
  • Customizable Logging Levels: Enables setting distinct log levels for file and console outputs, granting detailed control over the amount of logged information.
  • Console Logging Option: Provides an option to output logs to the console, beneficial during debugging and development phases.
  • Straightforward Configuration: Engineered for ease of setup with minimal required configurations, while retaining the flexibility for more advanced logging requirements.

Installation

RincewindLogger is a standalone Python module. Incorporate it directly into your project by adding rincewind_logger.py to your project's directory.

Usage

Setting Up the Logger

First, import and initialize the RincewindLogger, then configure it as per your requirements:

from rincewind_logger import RincewindLogger

# Initialize the logger
logger = RincewindLogger()

# Configure the logger
logger.setup(
    log_file_path='application.log',
    max_days=7,
    max_size_mb=10,
    log_level=logging.INFO,
    verbose=True
)

# Start logging
logger.log_info("An informational message.")
logger.log_error("An error message.")

Configuration Options

  • log_file_path (str): The path where the log file will be written.
  • max_days (int): The maximum number of days to keep the log files.
  • max_size_mb (int): The maximum size (in megabytes) a log file can grow to before being rotated.
  • log_level (int, optional): Sets the logging level for the file output. Defaults to logging.INFO.
  • verbose (bool, optional): If set to True, logs will also be printed to stdout. Defaults to False.
  • stdout_log_level (int, optional): Specifies the logging level for stdout output. If not set, it defaults to the value of log_level.

Logging Messages

To log messages, use the log_info and log_error methods:

  • log_info(message: str): Logs an informational message to the log file and, if verbose is True, to stdout.
  • log_error(message: str): Logs an error message similarly.

Verifying Logger Configuration

To check if the logger has been configured, you can use the is_configured property:

if logger.is_configured:
    print("Logger is properly configured.")
else:
    print("Logger configuration is pending.")

Advanced Configuration

The logger setup allows for advanced configurations, including setting up rotation policies based on file size and retention duration. This enables efficient management of log files, ensuring they do not consume excessive disk space over time.

Contributing

We welcome contributions to the RincewindLogger project. If you have suggestions, please feel free to open an issue or submit a pull request.

License

RincewindLogger is made available under the MIT License. See the LICENSE file in the project repository for more information.

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

rincewindlogger-0.1.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

rincewindlogger-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rincewindlogger-0.1.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.3.0

File hashes

Hashes for rincewindlogger-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c7f6eaae4cf6fb9f238407073751aaa5ba0eec1756b83ad2299027973227777b
MD5 57ec999f0734184c9b1a98630598c565
BLAKE2b-256 1c2dcbfebb43eea3237f4803e9ff7cb0b96dc571ba6ee37072499e185934e369

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rincewindlogger-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.3.0

File hashes

Hashes for rincewindlogger-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f9b0fcf7cca867e1a4a6c38a986ebc4ffd626f504c2e103034f08fb21acada1
MD5 12d20ce9f1ca6ef46a18ca8f10e18edc
BLAKE2b-256 a1571fc5f3020a32d17fcbd25b75822201dc2b781ab241c5bb5387258dd30214

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