Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

logging-commons

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logging-commons

Python Logging Commons

  • 0.1.22
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc