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
File details
Details for the file python_json_log_formatter-3.7.0.tar.gz
.
File metadata
- Download URL: python_json_log_formatter-3.7.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68b3a31188f1a6d1f17081e46b6bbe143bcac222c5ce39b8c0822f00e0b3b892 |
|
MD5 | f7f8c9cf6180766e8af53c7f72135143 |
|
BLAKE2b-256 | ce73e9397470e61aaa59d0ef88b3b377c26913b3999ddc9576a59421a9dd90a0 |
File details
Details for the file python_json_log_formatter-3.7.0-py3-none-any.whl
.
File metadata
- Download URL: python_json_log_formatter-3.7.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b0af7e1395ba998307bd312ffedcfd94ae7476bdab3d9fdeea53ce8d4743aea |
|
MD5 | c0798e82306a5bf9e5f4c51f70351b84 |
|
BLAKE2b-256 | 6398e22aa734a6f3a47b9e48f5691a532f91ac820a4d1076d53b0965cf6c62a3 |