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.2.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.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logpunch-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9c0b92a6bdac48a736918e8c4647d9244edeb541323fcdcdbb2a93533e992bca
MD5 458035180b927b668864ebb442c314c4
BLAKE2b-256 3ce05604a83a9d35ab9f0ca82b4da9e00969efa347af8a2d16be8a2f2e6bbb79

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logpunch-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e652c82a8da84916790fb36570d487cef320be637706b003dc3a34df228f20e6
MD5 22c1d1b7bc023a0f5d6a1d65bddf7333
BLAKE2b-256 c76b47dc702af3497cbd105fcbde3b177004e9e8b2b0e6761ee7c8d7ae413962

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