我是否需要显式记录哨兵在 Django 中工作的消息

发布于 2024-11-19 11:47:10 字数 224 浏览 7 评论 0原文

我已经安装了 Sentry 来记录消息。我是哨兵新手,所以我不知道它是如何工作的。

它是否只记录那些用记录器(“错误某事”)放入我的文件中的消息,或者发生什么错误,它会自动记录它

假设我没有在我的视图中编写任何日志语句。现在,如果我收到任何异常,那么哨兵会记录它,或者我必须对哨兵的每个异常进行编程

是否有任何方法可以自动记录所有错误而无需输入任何代码,因为我不知道会发生什么类型的异常

I have installed Sentry for messages logging. I am new to sentry so i don't how it works.

Does it logs only those messages which put in my files with logger ("error something") or whatever error occurs it automatically logs it

Suppose i have not written any log statement in my view. Now if i get any exception then will sentry logs it or i have to program every exception for sentry

is there any way to automatically logs all error without entering any code because i don't know what type of exceptions can occur

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等你爱我 2024-11-26 11:47:10

Sentry 自动捕获所有异常并记录它们。至于日志记录本身(使用记录器),默认情况下它不会捕获这些日志记录。你必须设置它。

您可以在此处查看如何设置日志记录。警告:一开始似乎确实很难做到。

编辑:摘自官方文档(07/26/2018):

与日志记录集成:
要与标准库的日志记录模块集成,并将所有 ERROR 及以上消息发送给 Sentry,可以使用以下配置:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'root': {
        'level': 'WARNING',
        'handlers': ['sentry'],
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s '
                      '%(process)d %(thread)d %(message)s'
        },
    },
    'handlers': {
        'sentry': {
            'level': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
            'tags': {'custom-tag': 'x'},
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django.db.backends': {
            'level': 'ERROR',
            'handlers': ['console'],
            'propagate': False,
        },
        'raven': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'sentry.errors': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
    },
}

用法: 记录用法的工作方式与 Django 外部的工作方式相同,
在额外数据中添加可选的请求密钥:

logger.error('There was some crazy error', exc_info=True, extra={
    # Optionally pass a request and we'll grab any information we can
    'request': request,
})

Sentry auto catches all exceptions and logs them. As for logging itself (using logger), it doesn't catch those by default. You have to set it up.

You may view how to setup logging here. Warning: it does seem difficult do to at first.

Edit: Excerpt from official docs (07/26/2018):

Integration with logging:
To integrate with the standard library’s logging module, and send all ERROR and above messages to sentry, the following config can be used:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'root': {
        'level': 'WARNING',
        'handlers': ['sentry'],
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s '
                      '%(process)d %(thread)d %(message)s'
        },
    },
    'handlers': {
        'sentry': {
            'level': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
            'tags': {'custom-tag': 'x'},
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django.db.backends': {
            'level': 'ERROR',
            'handlers': ['console'],
            'propagate': False,
        },
        'raven': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'sentry.errors': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
    },
}

Usage: Logging usage works the same way as it does outside of Django,
with the addition of an optional request key in the extra data:

logger.error('There was some crazy error', exc_info=True, extra={
    # Optionally pass a request and we'll grab any information we can
    'request': request,
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文