Skip to content

Instantly share code, notes, and snippets.

@RonenNess
Created January 17, 2018 11:33
Show Gist options
  • Save RonenNess/e6a46848f08e3dd0ea25f9d187088187 to your computer and use it in GitHub Desktop.
Save RonenNess/e6a46848f08e3dd0ea25f9d187088187 to your computer and use it in GitHub Desktop.
Django basic log config - creates file and console handlers and add all installed apps by default to the main log file.
# Dump this at the end of your setting file.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'INFO',
'filename': 'log.log',
'class': 'logging.handlers.RotatingFileHandler',
'maxBytes': 1024*1024*5,
'backupCount': 10,
'formatter': 'verbose'
},
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['file', 'console'],
'level': 'WARNING',
'propagate': True,
},
},
}
# create loggers for all apps
for installed_app_name in INSTALLED_APPS:
LOGGING['loggers'][installed_app_name] = {
'handlers': ['file', 'console'],
'level': 'DEBUG',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment