How can I configure logging in Django to use Sentry by default for all WARNING
and higher messages, but when I run a management command lower it to INFO
and add a console logger?
In normal operation (running the site via mod_python or uWSGI), I only care about WARNING
and higher. However, we have some management commands that we run via cronjobs, and I would like to collect their INFO
messages (in the management command, but also in deeper code) too in a logfile. Some of the management commands come from external libraries, I would prefer not to change them (to add extra initialization there). Ideally, I would like to detect in the settings module whether we are running via manage.py
or via WSGI.
The relevant part of my current LOGGING
dict:
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
}.
'sentry': {
'level': 'WARNING',
'class': 'raven.contrib.django.handlers.SentryHandler',
},
},