Supplements a default formatter configuration for machine-readable JSON logging and applies it
Project description
python-logger
Supplements a default formatter configuration for machine-readable JSON logging and applies it.
This module should be included as a sub-module in python projects with logging. Please avoid copy-pasting as no updates can be supplied that way.
Usage
- Install the module via the
requirements.txt
or per CLI:pip install python-json-log-formatter
- Please include the
PythonLogger
module, using afrom module import class
statement. - After the imports, please declare a version constant.
This constant should use semantic versioning, with a prepended date(YYYY/MM/DD)
.
Other examples, without the date, can be found here - Before any argument parsing or any other logging, the logger should be initialized
- In EVERY file, the logger needs to be imported using
LOGGER = logging.getLogger(__name__)
from python_json_log_formatter import PythonLogger
import logging
VERSION = "1.0.0 (2022/11/24)"
PythonLogger.setup_logger(VERSION)
LOGGER = logging.getLogger(__name__)
Optionally, it is also possible to change the log level:
from python_json_log_formatter import PythonLogger
import logging
VERSION = "1.0.0 (2022/11/24)"
PythonLogger.setup_logger(VERSION, logging.DEBUG)
LOGGER = logging.getLogger(__name__)
Features
Sets the logging format for the root logger and thus for every child logger.
In EVERY file where logging happens, please use LOGGER = logging.getLogger(__name__)
to get an individual logger.
Allows printing exception information on any logging level, not only on the EXCEPTION
level but also for INFO
or DEBUG
.
Supply exec_info
to print these.
Sets pipeline_status
and job_status
to failed
on CRITICAL
, supports minor logging levels (41, etc).
To disable the logging on local machines, supply disable_log_formatting=True
when configuring the logger.
Alternatively, without code changes, you can supply the ENV var DISABLE_LOG_FORMATTING"=True
to generally disable it.
Every attribute of the LogRecord will be included in the formatted message unless specified in the excluded_logging_context_keys
list.
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
Built Distribution
Hashes for python_json_log_formatter-3.2.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 110737705671de3c2e3979ee96864d849c8c147f8e41df6a7451ecd0c5883193 |
|
MD5 | 967f975afeacb9b0b54f371c58dcf29c |
|
BLAKE2b-256 | f8a641850113b16bc2ea95c3b7a740637944d812fc968a41d646683f43666c3c |
Hashes for python_json_log_formatter-3.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d959aeb799619c24ff1be5104abaeb85a6372293eed0aa7f7fb27ad8a5920ff |
|
MD5 | cae58e5caa87d731208585e82f7beda9 |
|
BLAKE2b-256 | 19f3ac3b16a6fb75cf6a412d3bf62ceedeab1538f9cf6c822049f3d0f0c07128 |