Chr*_*nne 17 python logging uwsgi
我有一个在uWSGI后面运行的python 2 flask app,由supervisord管理.烧瓶应用程序正在将日志写入sys.stdout.然后由uWSGI接收这些日志并由supervisord写入文件.uWSGI日志写入/ dev/stderr.请参阅下面的supervisord conf.
[program:uwsgi]
command = uwsgi --ini /etc/uwsgi.conf --master
directory = /app
autostart = true
autorestart = true
stdout_logfile = /var/log/myapplication/application.log
stdout_logfile_maxbytes = 50000000
stdout_logfile_backups = 3
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
stopsignal = INT
Run Code Online (Sandbox Code Playgroud)
这很棒!我很好地分离了应用程序日志和uWSGI日志.
我现在已升级到python 3.这一切都很顺利,除了应用程序日志现在最终在uWSGI的stderr中,与uWSGI日志混合在一起.
我已经拖网了uWSGI码头,并且无法在python 2和python 3之间找到这种变化的原因.
我在定义套接字时尝试重定向,就像这里建议的http://lists.unbit.it/pipermail/uwsgi/2016-February/008383.html那样只是将所有内容(应用程序和uWSGI日志)重定向到/dev/null
.
我也找到了这个http://lists.unbit.it/pipermail/uwsgi/2016-January/008353.html但是找不到关于pyimport-shared的任何信息.
有谁知道可能会发生什么?
如果它有帮助,我的uWSGI conf就在这里.
[uwsgi]
uid = www-data
gid = www-data
module = application:application
socket = /run/uwsgi.sock
single-interpreter = true
enable-threads = true
buffer-size = 16384
processes = 4
Run Code Online (Sandbox Code Playgroud)
谢谢
当您运行 4 个进程时,我猜您正在使用 --master 标志运行 uWsgi。在这种情况下,您可能希望使用标志将登录进程委托给主进程
--日志主控
不知何故,这为我解决了问题。
来自https://github.com/unbit/uwsgi/blob/d960f8fdc36b33c60b7291ca8e32dbb5df22cf15/core/uwsgi.c#L794
{"log-master", no_argument, 0, "将日志记录委托给主进程", uwsgi_opt_true, &uwsgi.log_master, UWSGI_OPT_MASTER|UWSGI_OPT_LOG_MASTER},
另外一个选择:
来自 https://github.com/unbit/uwsgi/issues/1601
如果您需要拆分 stdout 和 stderr,只需使用启动时执行的 python 代码重新映射它们的文件描述符即可。它们(fd:1和2)指向相同的资源,但如果您被迫supervisord并需要拆分它们,唯一的解决方案是关闭并重新打开相关文件。
如果您更喜欢 python 日志子系统而不是使用 unix 文件描述符,请考虑到您也有“python”记录器。
或者,你可以从堆栈中删除supervisord:)
归档时间: |
|
查看次数: |
2172 次 |
最近记录: |