为什么在使用 paste.deploy 中的 loadapp 时没有使用我的日志级别? [英] Why is my log level not being used when using loadapp from paste.deploy?
问题描述
我想在生产 pyramid 网络项目中临时打开调试消息,因此我调整了 production.ini
文件,将其推送到 Heroku 并且只看到错误和警告级别的消息.
I want to temporailiy turn on debug messages in a production pyramid web project so I adjusted the production.ini
file, pushed it to Heroku and saw only error and warn level messages.
所以我想,这似乎很奇怪,因为如果我在本地 PC 上启动如下所示的金字塔应用程序,我会收到所有日志级别的消息.
So I thought, that seems odd since if I start the pyramid application like the following on my local PC I get all the log level messages.
env/bin/pserve production.ini
好的,这并不是它在 Heroku 上的运行方式,它实际上是从 一点 python 看起来像这样(在名为 runapp.py
的文件中):
OK, so that's not exactly how it runs on Heroku, it is actually run from a little bit of python that looks like this (in a file called runapp.py
):
import os
from paste.deploy import loadapp
from waitress import serve
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app = loadapp('config:production.ini', relative_to='.')
serve(app, host='0.0.0.0', port=port)
现在,如果我在本地 PC 上执行此操作,肯定会得到与部署到 Heroku 时相同的行为(不足为奇).
Now, sure enough if I do this on my local PC I get the same behavior as when it is deployed to Heroku (hardly surprising).
python runapp.py
我的问题是,我在这里错过了什么?为什么以第二种方式运行它会导致除了 ERROR 和 WARN 之外没有日志消息被输出到标准输出?当然,因为它使用相同的 production.ini
文件,它应该像我使用 pserve
进程一样工作吗?
My question is, what am I missing here? Why does running it the second way result in no log messages other than ERROR and WARN being output to standard out? Surely, since it is using the same production.ini
file it should work the same as if I use the pserve
process?
这是我在 production.ini
中的日志记录部分:
Here is my logging section from production.ini
:
###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###
[loggers]
keys = root, test
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = DEBUG
handlers = console
[logger_test]
level = DEBUG
handlers = console
qualname = test
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = DEBUG
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
推荐答案
PasteDeploy 实际上并不负责配置日志记录.这是 INI 文件具有双重用途的一个小怪癖.有 PasteDeploy 关心的部分,还有 logging.config.fileConfig
关心的部分,两者都必须运行才能完全加载 INI 文件.
PasteDeploy does not actually assume responsibility for configuring logging. This is a little quirk where the INI file is dual-purposed. There are sections that PasteDeploy cares about, and there are sections that logging.config.fileConfig
cares about, and both must be run to fully load an INI file.
如果您遵循金字塔包装器来执行此操作,您会:
If you follow the pyramid wrappers for doing this, you'd do:
pyramid.paster.setup_logging(inipath)
pyramid.paster.get_app(inipath)
您使用这些而不是自己做的主要原因是,当 inipath
包含像 development.ini#myapp
,fileConfig
会崩溃.
The main reason you would use these instead of doing it yourself is that they support doing "the right thing" when inipath
contains a section specifier like development.ini#myapp
, which fileConfig
would crash on.
这篇关于为什么在使用 paste.deploy 中的 loadapp 时没有使用我的日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!