Skip to content

Instantly share code, notes, and snippets.

@cb109
Last active March 8, 2021 00:10
Show Gist options
  • Save cb109/db64aff55e8d09a4ce707c586e71a08c to your computer and use it in GitHub Desktop.
Save cb109/db64aff55e8d09a4ce707c586e71a08c to your computer and use it in GitHub Desktop.
logging.dictConfig for colored logging
# 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