Skip to content

Instantly share code, notes, and snippets.

@dmy3k
Created January 23, 2014 10:37
Show Gist options
  • Save dmy3k/8576421 to your computer and use it in GitHub Desktop.
Save dmy3k/8576421 to your computer and use it in GitHub Desktop.
Part of django settings.py as a sample logging setup
import os.path
p = lambda *x: os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', *x))
# Main configuration goes here
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': p('../logs/app.log'),
'maxBytes': 1024 * 1024 * 5,
'backupCount': 3,
'formatter': 'standard',
},
'console':{
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'standard'
},
},
'loggers': {
'django': {
'handlers':['console'],
'propagate': True,
'level':'WARN',
},
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'': {
'handlers': ['logfile'],
'level': 'DEBUG' if DEBUG else 'ERROR',
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment