6

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!

rabbid
  • 5,465
  • 7
  • 26
  • 37
  • any updates on this? I have a similar issue, except Sentry logging works fine on my dev server but not my production server. My production has the exact same symptoms listed above. – Cory Walker Jun 08 '11 at 03:24
  • Where you get logger to save warning and when adding Sentry handler is executed? Because it can be not executed on production if you use it in manage.py, for example. – Kriplins Jun 13 '11 at 15:49
  • I add the Sentry logger right before I log the warning, so I'm sure it's getting executed. I don't know why it would work on my dev server and not my production server, though. – Cory Walker Jun 14 '11 at 02:05
  • I'm very interested in that answer too. – Bite code Jun 14 '11 at 07:12

3 Answers3

4

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('').

Reinout van Rees
  • 13,486
  • 2
  • 36
  • 68
3

Try to add:

logger.setLevel(logging.DEBUG)

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

Liorsion
  • 582
  • 5
  • 9
  • Thanks for your reply. Unfortunately that did not work for me. 404s and 500s, as well as other exceptions, are recorded just fine though... any other ideas? Thanks! – rabbid Apr 22 '11 at 10:26
  • A little update. Not only did that not work, that line of code actually kills my Django dev server. When I comment it out, things work fine again. Crazy. – rabbid Apr 22 '11 at 11:48
0

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.

Kriplins
  • 192
  • 9