Skip to main content

Logging with context (contextual logging)

This library provides utilities to easily add context to logging messages and to show them, promoting a logging style that separates the log message from its contextual values.

It helps you turning this:

logger.info("Reading user %s posts", user_id)
posts = get_posts(user_id)
logger.info("User %s have %d posts", user_id, len(posts))

Into this:

with add_global_context({"user_id": user_id}):
    logger.info("Reading user posts")
    posts = get_posts(user_id)
    logger.info("User posts readed", extra={"posts_count": len(posts)})

Documentation

You can read the docs at https://terseus.github.io/python-logging-with-context/

License

MIT

Download files

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

Source Distribution

logging_with_context-0.2.0.tar.gz (57.6 kB view details)

Uploaded Source

Built Distribution

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

logging_with_context-0.2.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file logging_with_context-0.2.0.tar.gz.

File metadata

File hashes

Hashes for logging_with_context-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f77e93154d5b51222676b93253fd805014341c91bda1e454803a1b5b266dd6dc
MD5 c71654a50250fdda18a8319a104dc267
BLAKE2b-256 5c671a199affbec60add7f030f4ed8288185fbdc01dccb807d6cdda4a5106988

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for logging_with_context-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d00a51e84a2c395102ee8a34c9c730732b418e2507221b6e9e0684fb3a87db6
MD5 4d9794137adf9b223a5e7a9b91466d79
BLAKE2b-256 bc1642f9ad0178858028159e5077f4219a8e7c347c24d9998a32e14f54da5fcc

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page