Skip to content

Instantly share code, notes, and snippets.

@dstegelman
Created November 1, 2012 02:14
Show Gist options
  • Save dstegelman/3991212 to your computer and use it in GitHub Desktop.
Save dstegelman/3991212 to your computer and use it in GitHub Desktop.
Django/Python Custom Logging config
LOG_LOCATION = './logs'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'json': {
'format':"{'message': %(message)s}"
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.handlers.SentryHandler',
'formatter': 'verbose'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'sqllog': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': LOG_LOCATION + "/sql.log",
'maxBytes': 5000000,
'backupCount': 2,
},
'myapp-log': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'json',
'filename': LOG_LOCATION + "/myapp.log",
'maxBytes': 5000000,
'backupCount': 2,
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'raven': {
'level': 'DEBUG',
'handlers': ['sentry'],
'propagate': False,
},
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['sqllog'],
'propagate': False,
},
'myapp': {
'level': 'DEBUG',
'handlers': ['myapp-log'],
}
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment