Python Logging Commons
Project description
Python Logging Tools
Usage
Logging Config
config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"()": "logging_commons.formatter.JsonFormatter",
"format_dict": {
"level": "levelname",
"timestamp": "asctime",
"logger_name": "name",
"module": "module",
"line": "lineno",
"message": "message",
"context": "mdc",
},
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "default",
"stream": "ext://sys.stderr",
},
},
"root": {
"level": "INFO",
"handlers": ["console"],
},
}
Example Output
{
"level": "INFO",
"timestamp": "2024-08-19T20:57:12.998Z",
"logger_name": "main",
"module": "main",
"line": 22,
"message": "Hello world!",
"context": {
"process_id": "fa0fb339-6bac-4b4b-ab17-3812689c71e4"
}
}
MDC Usage
import logging
from logging_commons.utils import MDC
LOGGER = logging.getLogger(__name__)
with MDC(process_id=):
LOGGER.info("Hello world!")
Special Thanks:
- Bogdan Mircea for the
JsonFormatter
code given in Stackoverflow
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
File details
Details for the file logging_commons-0.1.22.tar.gz
.
File metadata
- Download URL: logging_commons-0.1.22.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb11e3289e1ff2a4f3fab0f04e6b8e559325532d3344641afb4a84cb773819d |
|
MD5 | 4704629da49e2f6a01831dec5ee55b77 |
|
BLAKE2b-256 | b68d2762678f5128cf6f343571f03accb9cd883d4008b237da0c03e47e99ee58 |