Skip to main content

Python Logging Tools

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:

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

logging_commons-0.1.12.tar.gz (5.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page