Skip to main content

A high-performance, feature-rich Python logging library with JSON formatting, file rotation, and masking capabilities for sensitive data

Project description

Logger Kit

PyPI version Python Versions Build Status License: MIT

A powerful and flexible logging library for Python applications that provides structured logging, filtering capabilities, custom handlers, and asynchronous support. This library helps you implement comprehensive logging with features like data masking, async support, and structured output.

Table of Contents

Documentation

Features

  • Structured Logging: JSON-formatted logs for better parsing and analysis
  • Flexible Configuration: Easy-to-use log filtering and level management
  • Custom Handlers: Support for custom log handlers and formatters
  • Context Management: Temporary logging settings using context managers
  • Async Support: Asynchronous logging for improved performance
  • Data Masking: Advanced masking for sensitive information protection
  • Python 3.7+: Compatible with Python 3.7 and newer versions

Installation

Logger Kit is available on PyPI and can be installed with Poetry:

# Using Poetry (recommended)
poetry add logger-kit

# Using pip
pip install logger-kit

Quick Start

from logger_kit import Logger

# Create a logger instance
logger = Logger(name="app", level="INFO")

# Basic logging
logger.info("Hello, World!")

# Structured logging with additional context
logger.info("User logged in", extra={
    "user_id": 123,
    "ip": "192.168.1.1",
    "status": "success"
})

# Using context manager for temporary settings
with logger.context(level="DEBUG"):
    logger.debug("This is a debug message")

# Async logging
async def main():
    await logger.ainfo("Processing task", extra={"task_id": "123"})
    await logger.adebug("Task details", extra={"details": "..."})

Data Masking

Protect sensitive information with advanced data masking:

logger = Logger(name="secure_app")

# Configure masking rules
logger.key_masker.set_default_mask("[MASKED]")
logger.key_masker.add_exact_match("password")
logger.key_masker.add_exact_match("api_key", "[REDACTED]")
logger.key_masker.add_pattern("email", r"[^@]+@[^@]+\.[^@]+")

# Logging with sensitive data (will be automatically masked)
logger.info("User data", extra={
    "user": {
        "email": "user@example.com",
        "password": "secret123",
        "api_key": "ak_test_12345"
    }
})

Development

  1. Clone the repository:

    git clone https://github.com/rahmadafandi/logger-kit.git
    cd logger-kit
    
  2. Install dependencies with Poetry:

    poetry install
    
  3. Run tests:

    poetry run pytest
    

Requirements

  • Python ≥ 3.9
  • python-json-logger ≥ 2.0.0
  • aiofiles ≥ 0.8.0

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to your branch
  5. Create a Pull Request

Please ensure your code follows our style guide and includes appropriate tests.

Support

For support, please:

Author

Rahmad Afandi (rahmadafandiii@gmail.com)

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

logger_kit-0.0.3.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file logger_kit-0.0.3.tar.gz.

File metadata

  • Download URL: logger_kit-0.0.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

File hashes

Hashes for logger_kit-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1829f2a27c235963be612a960b6260525e6915f27ca84ab4c3cd78d6406a5cb3
MD5 f57ccb3f86a92d60448e6d4fcc0d9242
BLAKE2b-256 c1f9c30dc426267443a207aa7c65a7a2900f279dbb9d5927953a36b43fea7ca0

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