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!
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('')
.
Try to add:
logger.setLevel(logging.DEBUG)
after the logging.getlogger, it works for me on dev env.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With