gpt4 book ai didi

django - 正确的日志配置以禁用 django 错误电子邮件

转载 作者:行者123 更新时间:2023-12-03 07:38:19 25 4
gpt4 key购买 nike

我刚刚让哨兵在我的环境中工作,我尝试调整我的日志记录以使其停止发送错误电子邮件,但它仍然如此,我不明白为什么。我的日志配置是:

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,},
},
}

这里有没有遗漏的部分?我不知道那怎么可能发送电子邮件。我应该考虑另一个配置变量吗?

更新 :我注意到的一件事是我现在收到纯文本错误电子邮件,而不是以前收到的 HTML 电子邮件。当我调整日志配置时,情况发生了变化,但我不知道为什么,谷歌搜索似乎没有透露任何信息。

最佳答案

Django 设置了一个 default mail_admins处理程序,您不能简单地在 handlers 中替换它部分,所以如果你想摆脱它,你需要覆盖 handlers在根记录器中:

All loggers except django.server propagate logging to their parents, up to the root django logger. The console and mail_admins handlers are attached to the root logger to provide the behavior described above.


LOGGING = {
'loggers': {
'django': {
'handlers': [],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': False,
},
},

}


[编辑] 修复了关于覆盖处理程序类的错误声明,遗憾的是它没有按预期工作,似乎以某种方式进行了硬编码(太忙而无法在 django 代码库中查找)。

关于django - 正确的日志配置以禁用 django 错误电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62096528/

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