A Python package that provides ready-to-use logging configuration with enhanced formatters, and automatic directory creation. Simplifies logging setup with sensible defaults while supporting custom configurations.
- Millisecond-precision timestamps in log output.
- Timezone-aware formatting (local or UTC with 'Z' suffix).
- YAML-based logging configuration for easy customization.
- Rotating file handler and console logging out-of-the-box.
- Automatic log directory creation for file handlers.
- Import and configure logging:
from default_logging import configure_logging
configure_logging()
- (Optional) Use your own config:
configure_logging(config_path="path/to/your_logging_config.yaml")
from default_logging import configure_logging
import logging
configure_logging()
logger = logging.getLogger(__name__)
logger.info("Hello, world!")
The default configuration is defined in default_logging/logging_config.yaml
:
- Formatters:
simple
: UTC timestamps, millisecond precision.simple_with_trace_context
: Adds OpenTelemetry trace info to each log line.
- Handlers:
console
: Logs to stdout.rotating_file
: Logs tologs/app.log
with rotation.
- Root logger:
- Level:
DEBUG
- Handlers: both console and file.
- Level:
You can customize the YAML config or provide your own.
Custom formatters in default_logging/millisecond_formatter.py
provide:
%f
for milliseconds%z
for timezone offset (+HH:MM
,-HH:MM
, orZ
for UTC)
The package is compatible with OpenTelemetry. Check example usage here, and then execute opentelemetry-instrument python app.py
with formatter simple_with_trace_context
to see logs that contain trace and span IDs.