Skip to content

Instantly share code, notes, and snippets.

Last active May 16, 2021
What would you like to do?
log-with-context example
import logging
import logging.config
from log_with_context import add_logging_context, Logger
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"json": {"()": "json_log_formatter.JSONFormatter"},
"handlers": {
"console": {
"formatter": "json",
"class": "logging.StreamHandler",
"loggers": {
"": {"handlers": ["console"], "level": "INFO"},
LOGGER = Logger(__name__)"First message. No context")
with add_logging_context(current_request="hi"):"Level 1")
with add_logging_context(more_info="this"):
LOGGER.warning("Level 2")"Back to level 1")
LOGGER.error("No context at all...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment