Skip to content

Instantly share code, notes, and snippets.

@AlexanderHott
Last active March 29, 2026 20:50
Show Gist options
  • Select an option

  • Save AlexanderHott/b14778766b28c4e8dfc8f68bea0d9c06 to your computer and use it in GitHub Desktop.

Select an option

Save AlexanderHott/b14778766b28c4e8dfc8f68bea0d9c06 to your computer and use it in GitHub Desktop.
Python logging config
# For an explanation and more advanced setup, see this video from mCoding https://www.youtube.com/watch?v=9L77QExPmI0
import logging
import logging.config
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {
"format": "[%(asctime)s .%(msecs)03d|%(levelname)s|%(name)s|%(filename)s:%(lineno)d] %(message)s",
"datefmt": "%Y-%m-%dT%H:%M:%S%z",
}
},
"handlers": {
"stdout": {
"class": "logging.StreamHandler",
"formatter": "simple",
"stream": "ext://sys.stdout",
# "level": "WARNING",
"level": "INFO",
# "level": "DEBUG",
},
},
"loggers": {
"root": {
"level": "DEBUG",
"handlers": [
"stdout",
],
}
},
}
)
logger = logging.getLogger("app")
# ...
logger.info(f"Something happened {var1=} {var2=}")
@alexzorzella
Copy link
Copy Markdown

alexzorzella commented Mar 22, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment