Skip to content

Instantly share code, notes, and snippets.

@adamghill
Created November 29, 2013 14:57
Show Gist options
  • Save adamghill/7706927 to your computer and use it in GitHub Desktop.
Save adamghill/7706927 to your computer and use it in GitHub Desktop.
Django logging configuration (with Sentry)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'root': {
'level': 'DEBUG',
'handlers': ['console', 'sentry'],
},
'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'
},
'sentry': {
'level': 'INFO',
'filters': ['require_debug_false', ],
'class': 'raven.handlers.logging.SentryHandler',
},
'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', 'sentry', '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', 'sentry', 'request_log', ],
'level': 'WARNING',
'propagate': False,
},
'raven': {
'handlers': ['console', ],
'level': 'ERROR',
'propagate': False,
},
'sentry.errors': {
'handlers': ['console', ],
'level': 'ERROR',
'propagate': False,
},
'requests.packages.urllib3.connectionpool': {
'handlers': ['null', ],
'level': 'ERROR',
'propagate': False,
}
}
}
@radzak
Copy link

radzak commented Aug 29, 2018

As described here '' in loggers section is overwritten by 'root' anyway, so there is no point to include it twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment