What's Your Project Like?
We would love to know about your line of business and how we can help you grow!
Setting up logging is crucial to monitoring any app. This way you know what works and what doesn't. If done correctly it will save a lot of time of debugging.
Django uses the pyhton logging module. Concepts to understand are loggers
, handlers
, filters
and formatters
:
Set up logging in settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
},
'root': {
'handlers': ['console'],
'level': 'WARNING',
},
'django': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
'someapp.urls': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
}
}
Set up logging in your app:
import logging
logger = logging.getLogger(__name__)
These resources are great for understanding why and how to use logging in Django: