Skip to content

Instantly share code, notes, and snippets.

@raphaelyancey
Created April 11, 2019 15:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelyancey/bf8b53a2dbf675f9c99cf39f9e52c224 to your computer and use it in GitHub Desktop.
Save raphaelyancey/bf8b53a2dbf675f9c99cf39f9e52c224 to your computer and use it in GitHub Desktop.
Example logging dictConfig for Python / Django and colorlog for colored logs
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
},
'formatters': {
'colored': {
'()': 'colorlog.ColoredFormatter', # colored output
# --> %(log_color)s is very important, that's what colors the line
'format': '%(log_color)s[%(levelname)s] %(asctime)s :: %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'colorlog.StreamHandler',
'formatter': 'colored',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/var/log/app/django.log',
'formatter': 'colored',
},
},
'loggers': {
'': {
'handlers': ['console', 'file'],
'level': 'DEBUG',
'propagate': False,
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment