gpt4 book ai didi

Python3 + Gunicon 19.9 + Django 2.0 不打印我的日志,但打印 django.request

转载 作者:行者123 更新时间:2023-12-01 08:18:33 28 4
gpt4 key购买 nike

我在 django 应用程序中添加了很多日志,但没有打印出来。当我不使用gunicorn时,我的日志会打印到std(仅manage.py runserver)python manager.py runserver 日志:

  2019-02-22 16:36:13,973 apscheduler.scheduler #INFO 162 Scheduler started
2019-02-22 16:36:13,974 management.startup_tasks #INFO 14 Scheduling Test task, to run every 5 seconds
2019-02-22 16:36:14,029 apscheduler.scheduler #INFO 878 Added job "Test" to job store "default"

以下是我的 Django 日志记录设置

  LOGGING_CONFIG = None
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"console": {
# exact format is not important, this is the minimum information
"format": "%(asctime)s %(name)-12s #%(levelname)-3s %(lineno)d %(message)s"
}
},
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "console"}
},
"loggers": {
"": {"level": logging.INFO, "handlers": ["console"]},
"scheduler": {
"level": logging.INFO,
"handlers": ["console"],
# required to avoid double logging with root logger
"propagate": False,
},
"django.request": {
"handlers": ["console"],
"level": logging.INFO, # change debug level as appropiate
"propagate": False,
},
},
}
)

这不是命令:

 pipenv run gunicorn scheduler.wsgi:application --log-file -

这是我看到的唯一日志

  [2019-02-22 16:32:17 -0800] [44478] [INFO] Starting gunicorn 19.9.0
[2019-02-22 16:32:17 -0800] [44478] [INFO] Listening at: http://127.0.0.1:8000 (44478)
[2019-02-22 16:32:17 -0800] [44478] [INFO] Using worker: sync
[2019-02-22 16:32:17 -0800] [44487] [INFO] Booting worker with pid: 44487
2019-02-22 16:32:36,828 django.request #WARNING 228 Not Found: / <---- I went to the home page
2019-02-22 16:32:39,416 django.request #WARNING 228 Not Found: / <--- I went to the home page

最佳答案

您需要添加记录器gunicorn.info以在控制台输出中显示记录器。例如:

LOGGING_CONFIG = None
logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"console": {
# exact format is not important, this is the minimum information
"format": "%(asctime)s %(name)-12s #%(levelname)-3s %(lineno)d %(message)s"
}
},
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "console"}
},
"loggers": {
"": {"level": logging.INFO, "handlers": ["console"]},
"scheduler": {
"level": logging.INFO,
"handlers": ["console"],
# required to avoid double logging with root logger
"propagate": False,
},
"django.request": {
"handlers": ["console"],
"level": logging.INFO, # change debug level as appropiate
"propagate": False,
},
"gunicorn.info": { # Show gunicorn info
"handlers": ["console"],
"level": logging.INFO,
"propagate": False,
},
"gunicorn.error": { # show gunicorn errors
"handlers": ["console"],
"level": logging.DEBUG,
"propagate": False,
},
},
}
)

关于Python3 + Gunicon 19.9 + Django 2.0 不打印我的日志,但打印 django.request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54837034/

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