Skip to main content

Supplements a default formatter configuration for machine-readable JSON logging and applies it

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

python-logger

IMPORTANT - DEPRECATION WARNING: This module is deprecated and will be archived. Do not use. Use a self-written alternative or fork this repository.

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

  1. Install the module via the requirements.txt or per CLI: pip install python-json-log-formatter
  2. Please include the PythonLogger module, using a from module import class statement.
  3. 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
  4. Before any argument parsing or any other logging, the logger should be initialized
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_json_log_formatter-3.7.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

python_json_log_formatter-3.7.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file python_json_log_formatter-3.7.1.tar.gz.

File metadata

File hashes

Hashes for python_json_log_formatter-3.7.1.tar.gz
Algorithm Hash digest
SHA256 96943d6519d95279f984f12517d29a92cbd611f4e52617c02785065ada1c6676
MD5 aaa34bbd39fb08aa90a02b64af3c2deb
BLAKE2b-256 cda29710bce400a8268453c30846f8ab0305c40e99f5353243f379739d41b596

See more details on using hashes here.

File details

Details for the file python_json_log_formatter-3.7.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_json_log_formatter-3.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d708972c3a324991cd22c39ba0b76bb4fbdef438fe939aa70f8c8d6fccdda986
MD5 de624a5a7ae716428f7aaa805f1ad799
BLAKE2b-256 b59435f541fcd859f34112247769780ef2bbf4ca646189264cbd8e4cd975bf47

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