简体   繁体   English

如何在Sentry Python SDK中定义日志记录级别

[英]How to define logging level in Sentry Python SDK

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. 我试图在Sentry.io中获得一些信息(INFO级别),这些信息来自Django中的视图,但我不确定如何实现。 This is what I have tried : 这是我尝试过的:

In settings.py 在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 在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. 使用此代码,我在Sentry中看不到我的事件信息。 If I call logger.error(###) it shows this event and I have the red "error" flag, like expected with error level. 如果我调用logger.error(###),它将显示此事件,并且我有红色的“错误”标志,如预期的错误级别。

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 使用logger.error(###)它显示此事件,并且我在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. 谢谢你的帮助。

您应该将记录器的级别设置为INFO:

logger.setLevel(logging.INFO)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM