Skip to content

Instantly share code, notes, and snippets.

@paul-schwendenman
Last active December 18, 2015 16:58
Show Gist options
  • Save paul-schwendenman/5814723 to your computer and use it in GitHub Desktop.
Save paul-schwendenman/5814723 to your computer and use it in GitHub Desktop.
A sample logging setup for django
SITE_ROOT = '/your/path'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': SITE_ROOT + "/logfile",
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
'console':{
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'standard',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'django': {
'handlers':['console', 'logfile'],
'propagate': True,
'level':'WARN',
},
'django.db.backends': {
'handlers': ['logfile', 'console'],
'level': 'WARN',
'propagate': False,
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment