Python logging library with JSON formatting support
Project description
ADC Logger
A flexible and configurable Python logging library with support for JSON formatting and colored console output.
Features
- JSON Logging: Structured JSON log output with timestamps, log levels, and messages
- Colored Console Output: Beautiful colored logging using
colorlog - Flexible Configuration: Easy-to-use configuration classes for formatters, handlers, and loggers
- Multiple Formatters: Support for JSON, generic colored, and access log formats
- Extensible: Easy to extend with custom formatters and handlers
Installation
pip install -e .
Quick Start
from adc_logger import BaseLoggingConfig
import logging
# Create a custom configuration
config = BaseLoggingConfig()
# Add a logger
from adc_logger.configs import LoggerConfig
config.loggers.append(
LoggerConfig(
name="my_app",
level="INFO",
handlers=["console_json"]
)
)
# Setup logging
config.setup_logging()
# Use the logger
logger = logging.getLogger("my_app")
logger.info("Hello, World!")
Configuration
Formatters
The library provides three built-in formatters:
- JSON Formatter: Outputs structured JSON logs
- Generic Formatter: Colored console output with standard format
- Access Formatter: Simplified format for access logs
Handlers
Built-in handlers include:
console_json: JSON output to consoleconsole_generic: Colored output to consoleconsole_access: Access log format to console
Custom Configuration
You can create custom formatters, handlers, and loggers:
from adc_logger.configs import FormatterConfig, HandlerConfig, LoggerConfig
# Custom formatter
custom_formatter = FormatterConfig(
name="custom",
format="{asctime} - {name} - {levelname} - {message}",
datefmt="%Y-%m-%d %H:%M:%S"
)
# Custom handler
file_handler = HandlerConfig(
name="file_handler",
formatter="json",
class_=logging.FileHandler,
filename="app.log"
)
# Custom logger
app_logger = LoggerConfig(
name="my_app",
level="DEBUG",
handlers=["console_json", "file_handler"]
)
Examples
Basic Usage
from adc_logger import BaseLoggingConfig
import logging
config = BaseLoggingConfig()
config.setup_logging()
logger = logging.getLogger(__name__)
logger.info("Application started")
logger.error("An error occurred")
JSON Logging
from adc_logger import BaseLoggingConfig
from adc_logger.configs import LoggerConfig
import logging
config = BaseLoggingConfig()
config.loggers.append(
LoggerConfig(
name="api",
handlers=["console_json"]
)
)
config.setup_logging()
logger = logging.getLogger("api")
logger.info("API request received", extra={"user_id": 123, "endpoint": "/users"})
Multiple Handlers
from adc_logger import BaseLoggingConfig
from adc_logger.configs import LoggerConfig, HandlerConfig
import logging
config = BaseLoggingConfig()
# Add file handler
file_handler = HandlerConfig(
name="file_handler",
formatter="json",
class_=logging.FileHandler,
filename="app.log"
)
config.handlers.append(file_handler)
# Configure logger with multiple handlers
config.loggers.append(
LoggerConfig(
name="my_app",
handlers=["console_generic", "file_handler"]
)
)
config.setup_logging()
Development
Project Structure
adc_logger/
├── __init__.py # Main exports
├── main.py # BaseLoggingConfig class
├── configs.py # Configuration classes
└── formatters.py # Custom formatters
Dependencies
colorlog>=6.7.0: For colored console output- Python 3.8+
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
adc_logger-0.1.0.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adc_logger-0.1.0.tar.gz.
File metadata
- Download URL: adc_logger-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69d64541d0e786234998e26b0e14d278c44d5e084fbada5b499798d3e4ef93c3
|
|
| MD5 |
3a1b2d9febccac3f296e9e6810078442
|
|
| BLAKE2b-256 |
b644b4a17ecf240a02ed9c7df577dac820e6ed548178932aa422aed36e7786ac
|
File details
Details for the file adc_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: adc_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f160ef13529312f08428031dd7ac7382694faf25695b0fb5646058ad6846221
|
|
| MD5 |
b96193792123bc0dc4c8c33e1b272ad8
|
|
| BLAKE2b-256 |
4515f6c88e6174dbcf7c965d6655ffc358d2ebdb2726e3b97e7422a514beac95
|