honeybadger-io / honeybadger-python

Send Python and Django errors to Honeybadger.
https://www.honeybadger.io/
MIT License
15 stars 25 forks source link

Add a log handler #82

Closed joshuap closed 3 years ago

joshuap commented 3 years ago

I would like to add a log handler that users can configure in their applications to automatically report error logs to Honeybadger.

Example:

except IndexError:
    logger.exception("Something bad happened")
logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'honeybadger': {
            'level': 'ERROR',
            'class': 'honeybadger.contrib.logger.HoneybadgerHandler',
        },
    },
    'loggers': {
        # root logger
        '': {
            'level': 'WARNING',
            'handlers': ['console', 'honeybadger'],
        },
    },
})

For more in-depth examples of how this will be used, see:

https://lincolnloop.com/blog/disabling-error-emails-django/ https://lincolnloop.com/blog/django-logging-right-way/ https://www.youtube.com/watch?v=ziegOuE7M4A&t=1s

Kelvin4664 commented 3 years ago

Hey @joshuap Are we limiting this to just exceptions? or info and warnings as well

joshuap commented 3 years ago

@Kelvin4664 sorry just got back from vacation. I think the idea is that we would report all logs that are >= to the configured level for our handler—so yeah, I imagine it could include info if the level were 'INFO' (but for most people it will be 'ERROR').