Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-sentry not recording warnings, errors, etc

I just installed django-sentry, and it catches exceptions just fine. However calls to logger.warning and logger.error are not being saved to Sentry for some reason.

Sentry implementation:

import logging
from sentry.client.handlers import SentryHandler

logger = logging.getLogger()
# ensure we havent already registered the handler
if SentryHandler not in map(lambda x: x.__class__, logger.handlers):
    logger.addHandler(SentryHandler())
# Add StreamHandler to sentry's default so you can catch missed exceptions
logger = logging.getLogger('sentry.errors')
logger.propagate = False
logger.addHandler(logging.StreamHandler())

logger call:

logger.warning("Category is not an integer", exc_info=sys.exc_info(), extra={'url': request.build_absolute_uri()})

Any ideas? Thanks!

like image 943
rabbid Avatar asked Apr 22 '11 03:04

rabbid


2 Answers

You're attaching the sentry stream handler to logging.getLogger('sentry.errors'). That means that logs to sentry.errors or below that will use that sentry stream handler.

But logs to 'my_app.something' don't end up there! So you're missing almost all log messages.

Solution: attach the stream handler to the root logger: logging.getLogger('').

like image 128
Reinout van Rees Avatar answered Sep 28 '22 03:09

Reinout van Rees


Try to add:

logger.setLevel(logging.DEBUG)

after the logging.getlogger, it works for me on dev env.

like image 39
Liorsion Avatar answered Sep 28 '22 01:09

Liorsion