-
-
Save AndrewJHart/8641072 to your computer and use it in GitHub Desktop.
Semi-advanced and useful logging config for django. Makes for good base to replace default Django config; great for app layout skeleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replaces default django logging config | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'class': 'django.utils.log.AdminEmailHandler' | |
}, | |
'null': { | |
'level':'DEBUG', | |
'class':'django.utils.log.NullHandler', | |
}, | |
'console':{ | |
'level':'DEBUG', | |
'class':'logging.StreamHandler', | |
'formatter': 'verbose' | |
}, | |
'logfile': { | |
'level':'DEBUG', | |
'class':'logging.handlers.RotatingFileHandler', | |
'filename': os.path.join(ROOT_PATH, 'django.log'), | |
'maxBytes': 1024*1024*5, # 5MB | |
'backupCount': 0, | |
'formatter': 'verbose', | |
}, | |
}, | |
'formatters': { | |
'verbose': { | |
'format': '%(levelname)s|%(asctime)s|%(module)s|%(process)d|%(thread)d|%(message)s', | |
'datefmt' : "%d/%b/%Y %H:%M:%S" | |
}, | |
'simple': { | |
'format': '%(levelname)s|%(message)s' | |
}, | |
}, | |
'loggers': { | |
'myapp.request': { | |
'handlers': ['mail_admins'], | |
'level': 'ERROR', | |
'propagate': True, | |
}, | |
'myapp.tasks': { | |
'handlers': ['mail_admins'], | |
'level': 'ERROR', | |
'propagate': True, | |
}, | |
'myapp.management': { | |
'handlers': ['console', 'logfile'], | |
'level': 'DEBUG', | |
'propagate': True, | |
}, | |
'myapp.models': { | |
'handlers': ['console', 'logfile'], | |
'level': 'DEBUG', | |
'propagate': True, | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple & effective logging configuration.