Skip to main content

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.

Release files for logpunch 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logpunch 1.0.2
File Size Uploaded
logpunch-1.0.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logpunch 1.0.2
File Interpreter ABI Platform
logpunch-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / logpunch-1.0.2.tar.gz

Download URL logpunch-1.0.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9c0b92a6bdac48a736918e8c4647d9244edeb541323fcdcdbb2a93533e992bca
BLAKE2b-256 checksum
How to use checksums
3ce05604a83a9d35ab9f0ca82b4da9e00969efa347af8a2d16be8a2f2e6bbb79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release files / logpunch-1.0.2-py3-none-any.whl

Download URL logpunch-1.0.2-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e652c82a8da84916790fb36570d487cef320be637706b003dc3a34df228f20e6
BLAKE2b-256 checksum
How to use checksums
c76b47dc702af3497cbd105fcbde3b177004e9e8b2b0e6761ee7c8d7ae413962
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page