python - gunicorn - 未知日志输出到控制台
问题描述
我正在用 gunicorn 和烧瓶运行我的网络服务。我将日志输出设置为日志文件,但在控制台中发现了一条未知的日志记录:
[2021-04-19 14:26:42 +0800] [1717]: [INFO] POST http://127.0.0.1:9200/papers/_search [status:200 request:1.347s]
我在服务中使用了elasticsearch,这是发送到es服务器的请求。我希望将此信息打印在一个文件中,并尝试了一些方法,但都没有奏效。这是我的独角兽设置:
bind = "0.0.0.0:5001"
workers = 4
threads = 4
proc_name = "app"
logconfig_dict = {
'version':1,
'disable_existing_loggers': False,
"root": {
"level": "INFO",
"propagate": True,
"handlers": ["console"]
},
'loggers':{
"gunicorn.error": {
"level": "INFO",
"handlers": ["error_file"],
"propagate": False,
"qualname": "gunicorn_error"
},
"gunicorn.access": {
"level": "INFO",
"handlers": ["access_file"],
"propagate": False,
"qualname": "access"
}
},
'handlers':{
"error_file": {
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1024*1024*100,
"backupCount": 1,
"formatter": "generic",
"filename": "/home/wh/SearchEngine-test/log_file/gunicorn_error.log"
},
"access_file": {
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1024*1024*100,
"backupCount": 1,
"formatter": "generic",
"filename": "/home/wh/SearchEngine-test/log_file/gunicorn_access.log",
},
'console': {
'class': 'logging.StreamHandler',
#"maxBytes": 1024*1024*100,
#"backupCount": 1,
'level': 'INFO',
'formatter': 'generic',
#"filename": "/home/wh/SearchEngine-test/log_file/gunicorn_console.log"
},
},
'formatters':{
"generic": {
"format": "%(asctime)s [%(process)d]: [%(levelname)s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter"
}
}
}
更重要的是,当我使用命令运行 gunicorn 时:
gunicorn -w 4 --threads 4 -b 0.0.0.0:5001 main:app
我不再获得此记录。
谁能帮帮我?
谢谢!
解决方案
如果要将错误写入日志文件:
--error-logfile yourfilename or --log-file yourfilename
对于您的访问日志:
--access-logfile yourfilename
有关更多信息,请查看此文档。
推荐阅读
- javascript - 为什么这些方块在 setInterval 内只翻译一次而不是多次?
- amazon-web-services - 使用 AWS ECR 公共库运行 Docker
- ios - 如何解决颤振上的 pod install 错误?
- python - 如何发布我刚刚保存的带有 tweepy 的图片?
- google-cloud-platform - Flink-BigTable - 任何连接器?
- excel - Excel SUMPRODUCT 和动态文本条件
- r - 闪亮 - 带小时的滑块输入
- python - python tkinter“in”运算符不起作用
- javascript - 尝试与 React .js App 同时运行我的 node.js 服务器并得到:'ERR_MODULE_NOT_FOUND'
- java - 使用 for 循环反转二维数组