Skip to main content

This Python package provides a robust and customizable logger that simplifies the process of recording messages and events in your applications. It leverages the power of the `colorlog` library to enhance readability and debugging capabilities.

Project description

Custom Logger: Enhanced Logging for Your Python Applications

Introduction

This Python package provides a robust and customizable logger that simplifies the process of recording messages and events in your applications. It leverages the power of the colorlog library to enhance readability and debugging capabilities.

Key Features

  • Flexible Log Levels: Supports standard logging levels (DEBUG, INFO, WARNING, ERROR, and CRITICAL) to categorize messages based on severity.
  • Colorized Output: Leverages colorlog to display log messages in distinct colors, improving visual clarity.
  • File and Console Logging: Logs messages to a specified file and optionally to the console for immediate feedback.
  • Customizable Formatting: Control the appearance of log messages using formatters for both file and console output.
  • Dynamic Console Logging: Enable or disable console logging at runtime to manage verbosity during development.
  • Handler Management: Add, remove, or adjust logging handlers to tailor logging behavior.
  • Default Loggers: Provides convenient wrappers for standard logging methods (debug, info, warning, error, critical, and exception).
  • Session Logging: Decorator function log_session to enclose a block of code with logging messages for session tracking.
  • Log File Reading: Utility function read_log_file to conveniently read and display the contents of the log file.
  • Log File Clearing: Optional clear_log_file method to clear existing log data.

Installation

To install the custom_logger package from PyPI (the Python Package Index), use the following command in your terminal:

pip install custom_logger

Usage

  1. Import the Logger Class:

    from custom_logger import Logger
    
  2. Create a Logger Instance:

    logger = Logger(log_name='my_logger', log_file='app.log', log_to_console=True)
    
    • log_name: A descriptive name for your logger (e.g., 'my_logger').
    • log_file: The path to the log file where messages will be saved.
    • log_to_console (optional, defaults to True): Whether to log messages to the console.
  3. Log Messages:

    logger.log_message('info', 'This is an informative message.')
    logger.warning('This is a warning message.')
    logger.error('This is an error message.')
    logger.critical('This is a critical message.')
    
  4. Default Loggers:

    logger.info('This is a general message.')
    logger.warning('This requires attention.')
    logger.exception('An exception occurred!', exc_info=True)  # Optional exception info
    
  5. Session Logging:

    @logger.log_session
    def my_function():
        # Your code here
        logger.info('Processing completed.')
    

    The log_session decorator automatically logs the start and end of the function execution.

  6. Read Log File:

    logger.read_log_file()
    
  7. Clear Log File (optional):

    logger.clear_log_file()  # Use with caution
    

Advanced Usage

  • Dynamic Console Logging:

    logger.disable_console_logging()  # Disable console logging
    logger.enable_console_logging()   # Re-enable console logging
    
  • Handler Management:

    Refer to the source code for details on adding, removing, or modifying logging handlers.

Customization

For advanced customization, consult the source code to modify formatting options for file and console output or create custom handlers.

Contributing

We welcome contributions to improve this logger. Feel free to submit pull requests on GitHub!

License

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

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

ultra_logger-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

ultra_logger-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file ultra_logger-0.1.1.tar.gz.

File metadata

  • Download URL: ultra_logger-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for ultra_logger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4b49d177e361abb0962ce020038cd1979ddf597f8f21e9e4efb49076cf4641d2
MD5 b979845341a9fe215a71537dfb351c11
BLAKE2b-256 46ea2d65a7885087f046fc8653ea521f8cd2cd96479332f651abbd9dd469820b

See more details on using hashes here.

File details

Details for the file ultra_logger-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ultra_logger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d2b6000ba7f2396b803b134cca37705ff50e2edf7d65ce9ac7ed5797b74e5e08
MD5 22a8705b6d46c1f4c462506d1c063270
BLAKE2b-256 51bb8696ebe98d9e0f6e71efae1982f772ee5bc8e3cf798dd325eb449e121d75

See more details on using hashes here.

Supported by

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