Skip to content

Instantly share code, notes, and snippets.

@LeMeteore
Forked from adamghill/logging.py
Created December 2, 2015 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeMeteore/cc983c72408bd3c30be6 to your computer and use it in GitHub Desktop.
Save LeMeteore/cc983c72408bd3c30be6 to your computer and use it in GitHub Desktop.
Django logging configuration
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'root': {
'level': 'DEBUG',
'handlers': ['console', ],
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s: %(message)s'
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'django.utils.log.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false', ],
'class': 'django.utils.log.AdminEmailHandler'
},
'log': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'logs/web.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter': 'verbose',
},
'request_log': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': 'logs/web-request.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter': 'verbose',
},
},
'loggers': {
'': {
'handlers': ['console', 'mail_admins', 'log', ],
'level': 'DEBUG',
},
'django.db.backends': {
'handlers': ['console', ],
'level': 'ERROR',
'propagate': False,
},
'django': {
'handlers': ['null', ],
'propagate': True,
'level': 'INFO',
},
'django.request': {
'handlers': ['console', 'mail_admins', 'request_log', ],
'level': 'WARNING',
'propagate': False,
},
'requests.packages.urllib3.connectionpool': {
'handlers': ['null', ],
'level': 'ERROR',
'propagate': False,
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment