dcramer/sentry — pull request #376 by ronaldevers (2012-03-08 11:52:09+00:00)
Title: Improve compatibility with logbook

I'm trying to use logbook instead of logging to send log entries to Sentry. But logging and logbook use different integer log levels:

>>> import logging
>>> logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.FATAL
(10, 20, 30, 40, 50)
>>>
>>> import logbook
>>> logbook.DEBUG, logbook.INFO, logbook.NOTICE, logbook.WARNING, logbook.ERROR, logbook.CRITICAL
(1, 2, 3, 4, 5, 6)

Adding new entries works but there are some glitches in presentation. Using SENTRY_LOG_LEVELS fixes the "Level: " field in "AGGREGATE DETAILS" but the css classes for the colored circles with the count are wrong because they embed the log level.

This change does not use the log level directly in the css classes but rather the log level name. With this change, one should use SENTRY_LOG_LEVELS as follows to work with logbook.

SENTRY_LOG_LEVELS = (
(logbook.DEBUG, 'debug'),
(logbook.INFO, 'info'),
(logbook.NOTICE, 'info'),
(logbook.WARNING, 'warning'),
(logbook.ERROR, 'error'),
(logbook.CRITICAL, 'fatal'),
)

Notice that logbook has an extra level called NOTICE which I clobber onto INFO here. You could even use both logging and logbook if you add the same list to SENTRY_LOG_LEVELS for the log levels of logging.

By the way: we use logbook because with logging, if the Sentry server is unavailable, the raven client hangs, presumably waiting for a TCP timeout, bringing our app to a crawl. With logbook you can use the ZeroMQ or MultiProcessing handlers to offload the logging logic to a different thread or process. This way your main app runs more or less independently from the logging process.