Skip to main content

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.

Project description

default_logging test publish PyPI version

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.

Features

  • 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.

Usage

  1. Import and configure logging:
from default_logging import configure_logging

configure_logging()
  1. (Optional) Use your own config:
configure_logging(config_path="path/to/your_logging_config.yaml")

Example

from default_logging import configure_logging
import logging

configure_logging()
logger = logging.getLogger(__name__)
logger.info("Hello, world!")

Logging Configuration

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 to logs/app.log with rotation.
  • Root logger:
    • Level: DEBUG
    • Handlers: both console and file.

You can customize the YAML config or provide your own.

MillisecondFormatter

Custom formatters in default_logging/millisecond_formatter.py provide:

  • %f for milliseconds
  • %z for timezone offset (+HH:MM, -HH:MM, or Z for UTC)

OpenTelemetry Integration

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.

License

MIT License

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

default_logging-0.5.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

default_logging-0.5.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file default_logging-0.5.0.tar.gz.

File metadata

  • Download URL: default_logging-0.5.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for default_logging-0.5.0.tar.gz
Algorithm Hash digest
SHA256 9ee28acc5b97d46955e1152a4145ac990520372c63208e20badf5ae8d4c6fc3d
MD5 3602f2139be6d08010ca2f9eeee36c54
BLAKE2b-256 b10f9bf5c45d71c4b6b62b5f82ba82fb7abedc0945fc7df92f18c98b2d7a63a0

See more details on using hashes here.

File details

Details for the file default_logging-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: default_logging-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.11.0-1018-azure

File hashes

Hashes for default_logging-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8353ecef5867e758076bfe56f1267df21a16c765541dfcccddb98fc4488d9240
MD5 b2aed430e6ae5edec3be605308642d84
BLAKE2b-256 396fe46691597355e63aefd690b8ec085080024a775deadafff70c54466c32f2

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