UWSGI不会将应用程序标准输出重定向到标准输出,而仅重定向到文件

时间:2019-03-05 22:31:55

标签: docker flask uwsgi

我有一个在容器内运行的Flask应用程序,在其中使用StreamHandler()设置了日志记录,因此将日志发送到stdout。
当我的uwsgi.ini文件包含将日志重定向到文件的语句(通过使用logto)时,来自应用程序的日志就可以在与uWSGI日志混合的日志文件中找到(如预期的那样) )。

但是,当我从logto中删除uwsgi.ini时-因为我希望将那些日志发送到Docker容器stdout,所以只有uWSGI日志在Docker容器日志中可见,而应用程序日志则不可见。 (uWSGI日志甚至以前都在那里)

uwsgi.ini:

[uwsgi]
base = /app_home/app
wsgi-file = /app_home/app/wsgi.py
callable = app
socket = /tmp/uwsgi.sock
chmod-socket    = 666
# Log directory - we needed this to be turned off, so the logs are sent to STDOUT
# logto = /var/log/uwsgi/app.log
vacuum = true
master = true
processes = 3
enable-threads = true
uid = app
gid = app
master-fifo = /tmp/fifo0
master-fifo = /tmp/fifo1

chdir = /app_home/app

启用logto后,日志文件将包含应用程序的日志(应如此):

[2019-03-05 17:19:05,415] INFO in __init__: Initial starting of app...
2019-03-05 17:19:05,415 (9) - INFO - Initial starting of app...- [in ./app/__init__.py:128, function:create_app]
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1ad49b0 pid: 9 (default app)
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 9)
spawned uWSGI worker 1 (pid: 32, cores: 1)

一旦logto被禁用,则没有日志文件(如预期的那样),但是Docker容器日志中也没有应用程序日志。 docker容器看起来与以前完全相同:

2019-03-05T22:19:09.956784133Z 2019-03-05 17:19:09,956 CRIT Supervisor running as root (no user in config file)
2019-03-05T22:19:09.959701644Z 2019-03-05 17:19:09,959 INFO supervisord started with pid 1
2019-03-05T22:19:10.961366502Z 2019-03-05 17:19:10,961 INFO spawned: 'nginx' with pid 9
2019-03-05T22:19:10.963312945Z 2019-03-05 17:19:10,962 INFO spawned: 'uwsgi' with pid 10
2019-03-05T22:19:12.928470278Z 2019-03-05 17:19:12,928 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2019-03-05T22:19:12.928498809Z 2019-03-05 17:19:12,928 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

uWSGI文档显示默认情况下将日志发送到stdout / stderr(请参阅https://uwsgi-docs.readthedocs.io/en/latest/Logging.html),所以我真的看不到为什么应用程序的日志不会与uWSGI自己的日志一起发送到stdout的原因,但使用logto发送到文件。

编辑(已解决)
原来有两个问题:

  1. 由于uWSGI在具有Supervisor的Docker容器中运行,因此我需要使超级用户将uwsgi的stdout重定向到其stdout。
    administratord.conf:
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /app_home/app/uwsgi.ini --uid app --gid app --log-master
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

虽然它可以与其他应用程序(如NGinx)一起使用,但对于uWSGI而言还不够,请参阅步骤2:

  1. 必须将特殊标志(--log-master)添加到uWSGI才能将日志记录委派给主进程:
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /app_home/app/uwsgi.ini --uid app --gid app --log-master
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

哇,在Docker容器日志中可以看到Flask应用程序的日志。

0 个答案:

没有答案
相关问题