Skip to main content

python-log-router

A package that allows logs to be routed to different log handlers based on a discriminant. Each unique value of the discriminant is managed by a distinct handler.

Installation

pip install logrouter

Usage

Call logrouter.setup_logging() to setup the logging configuration by providing the configuration yaml absolute file path. You can also set the configuration path using an environment variable. Specify the name of the env variable by setting the env_path parameter.

For an example of a configuration file, refer to the default configuration file. You can specify the log handler to be used by replacing handlers.single_handler_class with the name of the handler. The default one is logrouter.logrouter.DefaultHandler, which inherits from logging.FileHandler.

The default logging configuration will route all the logs based on the discriminator field of the LogRecord object. To use the default configuration, call logrouter.setup_logging(use_default_config=True).

Examples

Run and look at the code and logs produced of the examples located at /examples to experience what you can achieve with logrouter.

Using different types of handlers

A new instance of single_handler_class handler class is used for each discriminator unique value. This instance receives the log level and the discriminator value when created. If you want to use a differnet handler class for some discriminant values, specify them in handlers.handlers_dict in the logging configuration file. See this example.

Metadata

Release files for logrouter 0.0.2

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

Source distribution (sdist)

Source distribution for logrouter 0.0.2
File Size Uploaded
logrouter-0.0.2.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for logrouter 0.0.2
File Interpreter ABI Platform
logrouter-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / logrouter-0.0.2.tar.gz

Download URL logrouter-0.0.2.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3a294821fb60bbf267d0058366ef0e6a11cfbc58c8fc03796ac72e4b87777ca7
BLAKE2b-256 checksum
How to use checksums
44af269e706e6f1f023e5ce7ac3da6203d5bd5b266bc8913bad28a399efda48f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / logrouter-0.0.2-py3-none-any.whl

Download URL logrouter-0.0.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a1c3fefa172d5ef154d52a3f47a0b257246e7d6698b34b761dcf7bd53baff79
BLAKE2b-256 checksum
How to use checksums
e5be0fbf54b31a7d83de7e4ba601d93de84d8a2fae7adfca2dc1b0bffbce85af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

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