Sea*_*ean 1 python uwsgi pyramid
首先,一点背景.我在emperor模式下在uWSGI下运行一个应用程序.uWSGI命令行:
uwsgi --master --emperor /etc/uwsgi --die-on-term --uid uwsgi --gid uwsgi
Run Code Online (Sandbox Code Playgroud)
我的应用程序的INI文件位于/ etc/uwsgi中,并在uWSGI启动时成功找到.我的应用程序的uwsgi和日志记录配置部分:
[uwsgi]
socket = /tmp/uwsgi.sock
master = true
processes = 8
threads = 4
harakiri = 60
harakiri-verbose = true
limit-post = 52428800
post-buffering = 8192
listen = 256
max-requests = 1000
buffer-size = 32768
no-orphans = true
logto = /var/log/uwsgi/my_app.log
log-slow = 1000
virtualenv = /usr/local/python/my_app
paste = config:%p
[loggers]
keys = root, my_app
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
[logger_my_app]
level = DEBUG
handlers =
qualname = my_app
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
Run Code Online (Sandbox Code Playgroud)
Nginx配置为代理该站点,并成功完成.该应用程序启动并运行正常.从Web浏览器访问它没有问题.当我尝试从我的应用程序中记录某些内容时,问题就出现了:
import logging
log = logging.getLogger(__name__)
log.info('hello world')
Run Code Online (Sandbox Code Playgroud)
在我的日志中,我看到以下内容,而不是"hello world":
无法找到记录器"my_app.my_module"的处理程序
似乎uWSGI没有从我的INI文件中获取日志记录配置.我见过人们建议在uWSGI命令行上使用"--ini-paste-logged my.ini"选项,但由于我使用的是emperor模式,这在我的情况下不起作用.
其他人建议从应用程序中调用pyramid.paster.setup_logging,但这似乎是一个非理想的解决方案.首先,在开发过程中,我使用pserve在本地运行app,自动调用setup_logging,因此我必须根据应用程序运行的环境有条件地调用它.其次,setup_logging需要配置文件的路径作为参数,我需要能够为登台和生产环境使用不同的配置,所以我似乎必须做一些事情,比如在配置文件中添加一个指定自身路径的设置.最好的解决方案.
知道我怎么能让uWSGI拿起我的日志记录配置而不会跳过一堆篮球?
把它想出来,也可以留给后人留下来,因为网上似乎有关于皇帝模式的珍贵内容.我将"paste-logger =%p"添加到我的INI文件的uwsgi部分,现在记录似乎正常.上下文的完整uwsgi部分:
[uwsgi]
socket = /tmp/uwsgi.sock
master = true
processes = 8
threads = 4
harakiri = 60
harakiri-verbose = true
limit-post = 52428800
post-buffering = 8192
listen = 256
max-requests = 1000
buffer-size = 32768
no-orphans = true
logto = /var/log/uwsgi/my_app.log
log-slow = 1000
virtualenv = /usr/local/python/my_app
paste = config:%p
paste-logger = %p
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2236 次 |
| 最近记录: |