Define logging level

python 3.5
sentry-sdk 0.8.0

Hello,

I’m trying to get in Sentry.io some informations (INFO level) coming from a view in Django and I’m not sure to understand how to make it. This is what I have tried :

In settings.py

sentry_logging = LoggingIntegration(
    level=logging.INFO,        
    event_level=logging.INFO
)
sentry_sdk.init(
    dsn="https://###",
    integrations=[DjangoIntegration(), sentry_logging],
    server_name="MyServerName",
)

In views.py

def myview(request, something):
    # Here I do something

    # Log some data
    logger.info('Interesting info !', extra={
         'something_modified': something_modified,
    })

With this code, I don’t see my event info in Sentry. If I call logger.error(###) it shows this event and I have the red “error” flag, like expected with error level.

So I tried :

def myview(request, something):
    # Here I do something

    # Log some data
    with configure_scope() as scope:
        scope.level = 'info'
        logger.info('Interesting info !', extra={
            'something_modified': something_modified,
        })
  • It doesn’t work either
  • With logger.error(###) it shows this event and I have a blue info flag in Sentry
  • But the other real errors now appear in blue too, which is a bit too monochrome

Some concepts from the documentation are still unclear for me, I may have mixed “context / scope / levels” together.

Thanks for your help.

I think your first attempt (without doing anything with scopes) is almost fine, but you have to run logger.setLevel(logging.INFO) as well. Note that this will send all info-logs of that logger to Sentry, which is possibly too much data. Consider using sentry_sdk.capture_message or create a separate logger.

1 Like

Thank you ! For now it’s exactly what I was looking for and I see only my own info logs. But I will consider using sentry_sdk.capture_message if it becomes problematic.