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())
logg开发者_Python百科er 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.
You can add FileHandler to 'sentry.errors' logger and the check if it contains some error on production. But really stdout should be wrote to server logs. Can check this.
精彩评论