gpt4 book ai didi

django - 我是否需要显式记录 Sentry 在 Django 中工作的消息

转载 作者:行者123 更新时间:2023-12-02 06:51:50 25 4
gpt4 key购买 nike

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

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

假设我没有写任何日志语句。现在,如果我收到任何异常,那么 Sentry 会记录它,或者我必须为 Sentry 编写每个异常

有没有办法在不输入任何代码的情况下自动记录所有错误,因为我不知道会发生什么类型的异常

最佳答案

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

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

编辑:摘自官方文档(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,
})

关于django - 我是否需要显式记录 Sentry 在 Django 中工作的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6634046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com