mli*_*ner 5 django error-handling sentry
我刚刚让哨兵在我的环境中工作,我尝试调整我的日志记录以使其停止发送错误电子邮件,但它仍然如此,我不明白为什么。我的日志配置是:
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": '%(levelname)s %(asctime)s (%(pathname)s %(funcName)s): "%(message)s"'
},
"simple": {"format": "%(levelname)s %(message)s"},
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "[%(server_time)s] %(message)s",
},
},
"handlers": {
"null": {"level": "DEBUG", "class": "logging.NullHandler",},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "simple",
},
"log_file": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"filename": "/var/log/courtlistener/django.log",
"maxBytes": "16777216", # 16 megabytes
"formatter": "verbose",
},
"django.server": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "django.server",
},
},
"loggers": {
# Disable SuspiciousOperation.DisallowedHost exception ("Invalid
# HTTP_HOST" header messages.) This appears to be caused by clients that
# don't support SNI, and which are browsing to other domains on the
# server. The most relevant bad client is the googlebot.
"django.security.DisallowedHost": {
"handlers": ["null"],
"propagate": False,
},
"django.server": {
"handlers": ["django.server"],
"level": "INFO",
"propagate": False,
},
# This is the one that's used practically everywhere in the code.
"cl": {"handlers": ["log_file"], "level": "INFO", "propagate": True,},
},
}
Run Code Online (Sandbox Code Playgroud)
这里有没有遗漏的部分?我不知道那怎么可能发送电子邮件。我应该考虑另一个配置变量吗?
更新:我注意到的一件事是我现在收到纯文本错误电子邮件,而不是以前收到的 HTML 电子邮件。当我调整日志配置时,情况发生了变化,但我不知道为什么,谷歌搜索似乎没有透露任何信息。
你的LOGGING配置对我来说看起来(几乎,看到最后)很好。我还能想到一些其他的事情。
也许您进行了更改,但不是在所有地方,您可能有其他应用程序、celery 进程、临时部署等在您忘记的地方运行。
也许还有其他东西(我不确定是什么......)正在配置这个日志处理程序。如果是这种情况,您可以禁用现有的记录器:
LOGGING = {
"disable_existing_loggers": True,
...
}
Run Code Online (Sandbox Code Playgroud)
但这不是一个好主意,禁用其他人的记录器,因此作为替代方案,您可以通过其他方式禁用它。
该ADMINS设置定义了将错误发送到的电子邮件地址,因此您只需将其设置为空列表即可禁用它:
ADMINS = []
Run Code Online (Sandbox Code Playgroud)
这应该相对安全,因为发送错误电子邮件是此设置的唯一用途 - 除非您或第三方应用程序正在使用它。
您还可能收到不是服务器错误而是 404 错误的电子邮件。确保您的MIDDLEWARE不包含BrokenLinkEmailsMiddleware. 还有一个类似的设置ADMINS,但它被称为MANAGERS:
MANAGERS = []
Run Code Online (Sandbox Code Playgroud)
您还应该检查默认的日志记录配置,以确保您在创建自己的LOGGING字典时没有错过任何内容。
我注意到的另一件事是,将LOGGING配置插入项目时,配置无法正确解析,因为 的值maxBytes应该是 int,而不是字符串。所以你也可以尝试改变:
"log_file": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"filename": "/var/log/courtlistener/django.log",
"maxBytes": "16777216", # 16 megabytes
"formatter": "verbose",
}
Run Code Online (Sandbox Code Playgroud)
到:
"log_file": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"filename": "/var/log/courtlistener/django.log",
"maxBytes": 16777216, # 16 megabytes
"formatter": "verbose",
}
Run Code Online (Sandbox Code Playgroud)