Merge pull request #549 from maciej-gol/celery_loglevel

Added config option for celery handler's logging level.
This commit is contained in:
Xavier Ordoquy 2015-02-28 12:43:15 +01:00
commit cb31cda60d
4 changed files with 23 additions and 3 deletions

View File

@ -16,6 +16,9 @@ tl;dr register a couple of signals to hijack Celery error handling
# hook into the Celery error handler
register_signal(client)
# The register_signal function can also take an optional argument `loglevel`
# which is the level used for the handler created. Defaults to `logging.ERROR`
register_signal(client, loglevel=logging.INFO)
A more complex version to encapsulate behavior:

View File

@ -206,6 +206,18 @@ client::
SENTRY_CLIENT = 'raven.contrib.django.raven_compat.DjangoClient'
SENTRY_CELERY_LOGLEVEL
~~~~~~~~~~~~~~~~~~~~~~
If you are also using Celery, there is a handler being automatically registered
for you that captures the errors from workers. The default logging level for
that handler is ``logging.ERROR`` and can be customized using this setting::
SENTRY_CELERY_LOGLEVEL = logging.INFO
RAVEN_CONFIG = {
'CELERY_LOGLEVEL': logging.INFO
}
Caveats
-------

View File

@ -36,13 +36,13 @@ def register_signal(client):
task_failure.connect(process_failure_signal, weak=False)
def register_logger_signal(client, logger=None):
def register_logger_signal(client, logger=None, loglevel=logging.ERROR):
filter_ = CeleryFilter()
if logger is None:
logger = logging.getLogger()
handler = SentryHandler(client)
handler.setLevel(logging.ERROR)
handler.setLevel(loglevel)
handler.addFilter(filter_)
def process_logger_event(sender, logger, loglevel, logfile, format,

View File

@ -221,7 +221,12 @@ def register_handlers():
logger.exception('Failed to install Celery error handler')
try:
register_logger_signal(client)
ga = lambda x, d=None: getattr(django_settings, 'SENTRY_%s' % x, d)
options = getattr(django_settings, 'RAVEN_CONFIG', {})
loglevel = options.get('celery_loglevel',
ga('CELERY_LOGLEVEL', logging.ERROR))
register_logger_signal(client, loglevel=loglevel)
except Exception:
logger.exception('Failed to install Celery error handler')