raven-python icon indicating copy to clipboard operation
raven-python copied to clipboard

SentryHandler cannot work with formatters

Open if-fi opened this issue 8 years ago • 2 comments

I have a use case where I need to apply formatter to the log messages, that SentryHandler sends to Sentry. In the code it looks like SentryHandles is formatting the message, but, actually the newly formatted message is not saved in the log record. Formatting works if we change line https://github.com/getsentry/raven-python/blob/af74e2f5c40b6b379d2c583a764fb6810fc1b819/raven/handlers/logging.py#L83 to

            record.message = self.format(record)

You can easily recreate reproduce the problem like this

from logging import Formatter
from raven.handlers.logging import SentryHandler

        sentry_handler = SentryHandler(client=client, level='ERROR')
        sentry_handler.setFormatter(Formatter('This is my beautifully formatted message: %(message)s'))
        logging.getLogger().addHandler(sentry_handler)

I am ready to send you a pull request for fixing this issue.

if-fi avatar Jul 20 '17 13:07 if-fi

@if-fi Pull request always welcome :)

ashwoods avatar Aug 08 '17 14:08 ashwoods

Hi, Glad to see someone else had this issue. Was this pull request ever merged? I am currently using version 6.9.0 and formatted messages still don't work.

rebekahocampo avatar Jul 20 '18 19:07 rebekahocampo