The moment you set DEBUG = False
in development server for Django, you will be clueless about what’s going on for every error your application may encounter. If you just want to show verbose error messages on the console (when you run the manage.py
built-in web server for Django, follow the simple steps below.
In your settings.py
, the default logging configuration may be configured for I don’t know, is it production ready? For Django starters, this will hide basic errors you may encounter. We are going to configure the LOGGING
dict to have the required formatters
, handlers
and loggers
. Below is my LOGGING
section of settings.py
.
LOGGING = { 'version': 1, 'disable_existing_loggers': False, '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': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose', }, }, 'loggers': { 'django.request': { # 'handlers': ['mail_admins'], 'handlers': ['console'], 'level': 'ERROR', 'propagate': True, }, } }
Please note that this is for development mode only and for those who run the build-in web server. For production purpose, change the settings for the appropriate logging.
LOGGING = {
‘version’: 1,
‘disable_existing_loggers’: False,
‘filters’: {
‘require_debug_false’: {
‘()’: ‘django.utils.log.ReuireDebugFalse’
}
Hi
That is my code, but i dont get it work, any idea??