Skip to main content

Logpunch is a lightweight Python package providing a customizable colored logger and enhanced exception handling with detailed error tracking — designed to streamline logging and debugging in data science and machine learning projects.

Project description

Logpunch

A lightweight Python package for Data Science and Machine Learning projects, offering a customizable colored logger and an advanced exception tracking system.

PyPI version License: MIT Python Version

Overview

logpunch is designed to streamline debugging and logging in data science and machine learning workflows. It provides:

  • A customizable logger with colored terminal output and file-based logging, configurable for different log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL).
  • A tracked exception class that automatically captures the file name, function name, and line number of errors, simplifying debugging.

Whether you're building ML pipelines or analyzing data, logpunch enhances traceability and monitoring with minimal setup.

Features

  • Flexible Logging: Log to both terminal and files with customizable formats and colors.
  • Automatic Error Tracking: Capture detailed context (file, function, line number) for exceptions.
  • Lightweight: Minimal dependencies for easy integration into any Python project.
  • Configurable: Adjust log levels and directories to suit your needs.

Requirements

  • Python 3.7 or higher
  • Pydantic
  • Colorama

Installation

Install logpunch via PyPI:

pip install logpunch

Usage

Setting Up the Logger

Configure and initialize the logger with a few lines of code:

from logpunch.customlogger import CustomLogger, LoggerConfig

# Define logger configuration
config = LoggerConfig(
    log_dir="logs",         # Directory for log files
    log_level="INFO"        # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
)

# Initialize logger
logger = CustomLogger(config).get_logger()

# Log messages
logger.debug("Debug message: useful for development.")
logger.info("Info message: pipeline started successfully.")
logger.warning("Warning message: disk space low.")
logger.error("Error message: file not found.")
logger.critical("Critical message: system crash!")

Log files are saved in the specified log_dir (e.g., logs/) with timestamps for easy tracking.

Using the Custom Exception

The TrackedException class enhances error handling by automatically capturing the context of where the error occurred:

from logpunch.customlogger import CustomLogger, LoggerConfig
from logpunch.customexception import TrackedException

# Logger setup
config = LoggerConfig(log_dir="logs", log_level="ERROR")
logger = CustomLogger(config).get_logger()

# Function with intentional error
def divide(a, b):
    if b == 0:
        raise TrackedException("Division by zero is not allowed.")
    return a / b

# Handle the exception
try:
    result = divide(10, 0)
except TrackedException as e:
    logger.error(str(e))

The logged error will include details like the file name, function name, and line number, e.g.:

ERROR: Division by zero is not allowed. (File: example.py, Function: divide, Line: 10)

Why Use logpunch?

  • Enhanced Debugging: Pinpoint errors quickly with detailed exception context.
  • Clear Logging: Colored logs improve readability during development and debugging.
  • Lightweight and Simple: Integrate into any project without heavy dependencies.
  • Customizable: Tailor logging behavior to your project’s needs.

Contributing

We welcome contributions! To get started:

  1. Fork the repository on GitHub.
  2. Clone your fork and create a new branch: git checkout -b feature-name.
  3. Make your changes and commit them: git commit -m "Add feature-name".
  4. Push to your fork: git push origin feature-name.
  5. Open a pull request with a clear description of your changes.

Please ensure your code follows PEP 8 guidelines and includes tests where applicable.

License

logpunch is licensed under the MIT License.

Contact

For questions or support, open an issue on GitHub or contact the maintainers at grvgulia007@gmail.com.

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

logpunch-1.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

logpunch-1.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file logpunch-1.0.1.tar.gz.

File metadata

  • Download URL: logpunch-1.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for logpunch-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0af8286ff206faf19150fbc37b77da1dd8974eb65c87e217fe80af193d9c4882
MD5 513618138bd41e3a2a5345ba145b0e4a
BLAKE2b-256 d80668a65e4b5bf670e0214064c71d40d7a60e4947985c9b952d8dc0bd02c847

See more details on using hashes here.

File details

Details for the file logpunch-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: logpunch-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for logpunch-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3a5336032957c3c6dfaa0c7379688f165554d6bc6be22321d1b71c3cd30254
MD5 b310cf87efbe53d6bdba02a9b12b483f
BLAKE2b-256 0c46c8faf3a9461040de31b2546a4cd36c66281249af0b6109c9b3f20a7f30a4

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