Last active
March 8, 2021 00:10
-
-
Save cb109/db64aff55e8d09a4ce707c586e71a08c to your computer and use it in GitHub Desktop.
logging.dictConfig for colored logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Prerequisites: | |
| # | |
| # $ pip install colorama colorlog | |
| LOGGING = { | |
| 'version': 1, | |
| 'disable_existing_loggers': False, | |
| 'formatters' : { | |
| 'colored': { | |
| '()': 'colorlog.ColoredFormatter', | |
| 'format': ('%(asctime)s %(log_color)s[%(levelname)s]' | |
| '%(reset)s%(bold_white)s %(name)s%(reset)s: ' | |
| '%(message)s'), | |
| 'datefmt': '%Y-%m-%d %H:%M:%S', | |
| 'log_colors': { | |
| "DEBUG": "bold_cyan", | |
| "INFO": "bold_green", | |
| "WARNING": "bold_yellow", | |
| "ERROR": "bold_red", | |
| "CRITICAL": "bold_purple" | |
| }, | |
| }, | |
| }, | |
| 'handlers': { | |
| 'colored_console': { | |
| 'class': 'logging.StreamHandler', | |
| 'formatter': 'colored', | |
| }, | |
| }, | |
| 'loggers': { | |
| 'myproject': { | |
| 'level': 'DEBUG', | |
| 'handlers': ['colored_console'], | |
| }, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment