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.2.tar.gz (6.2 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: logger_kit-0.0.2.tar.gz
  • Upload date:
  • Size: 6.2 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.2.tar.gz
Algorithm Hash digest
SHA256 4d75a17b4a280cc2a83eba3d9a097699edeca49ef337d25f4e178b7e808b9187
MD5 13620eadf0161279b11056f8ed8efa40
BLAKE2b-256 a1e440d032b1d43b3d5e9c971741fad8b4ec1a5b88718aceb263c866fec525f4

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