Skip to main content

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.

Metadata

Release files for logger-kit 0.0.3

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

Source distribution (sdist)

Source distribution for logger-kit 0.0.3
File Size Uploaded
logger_kit-0.0.3.tar.gz 6.1 kB Details

Release files / logger_kit-0.0.3.tar.gz

Download URL logger_kit-0.0.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1829f2a27c235963be612a960b6260525e6915f27ca84ab4c3cd78d6406a5cb3
BLAKE2b-256 checksum
How to use checksums
c1f9c30dc426267443a207aa7c65a7a2900f279dbb9d5927953a36b43fea7ca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

0.0.2

1 release file

0.0.1

1 release file

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