Skip to main content

Helper to add request id in logger and context

Project description

request-id-helper

CI codecov pypi downloads versions license

request-id-helper is a helper to add request id in logger and context.

Installation

request-id-helper is available on PyPI. Use pip to install:

$ pip install request-id-helper

Basic Usage

import logging
from request_id_helper import init_logger, set_request_id

logger = logging.getLogger(__name__)

LOGGING = {
    "version": 1,
    "disable_existing_loggers": 0,
    "formatters": {
        "default": {
            "()": "request_id_helper.RequestIdFormatter",
            "format": "[%(asctime)s] %(levelname)s [%(request_id)s] %(name)s | %(message)s",
            "datefmt": "%d/%b/%Y %H:%M:%S",
        }
    },
    "handlers": {
        "stdout": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "formatter": "default",
        },
    },
    "loggers": {
        "": {
            "handlers": ["stdout"],
            "propagate": True,
            "level": "INFO",
        },
    },
}


def main():
    init_logger(LOGGING)

    @set_request_id()
    def my_function() -> int:
        
        logger.info("Demo")

        return 10

    my_function()

if __name__ == "__main__":
    main()
    [17/Oct/2024 20:13:02] INFO [459cb386-5947-4eec-b3d8-266605f40444] __main__ | Demo

License

request-id-helper is developed and distributed under the Apache 2.0 license.

Reporting a Security Vulnerability

See our security policy.

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

request-id-helper-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

request_id_helper-0.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file request-id-helper-0.2.0.tar.gz.

File metadata

  • Download URL: request-id-helper-0.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for request-id-helper-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6ecb32087c49ad7b37c9a9373ed17402598b8af81ed1b04b0be1c7c22455ec6f
MD5 7d259b7b1b822a648effd1d5ac88ca3b
BLAKE2b-256 def8c1c2e44b9e28f1b382091afd094f7c4a8b0b1f991914580861e33e8f9105

See more details on using hashes here.

File details

Details for the file request_id_helper-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for request_id_helper-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b14cd7988925153bfa6e61ab09184c64ea51cb94ac9a9340adf5d8947b822887
MD5 db0525d4cb0322777e93f660d26da07d
BLAKE2b-256 15f4ecbc8c820b84d070e9b22028b95e0082f2d8110342f5d1a83a5b017b7098

See more details on using hashes here.

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