问题描述
我正在运行一个[程序:x],它会打印/sys.stdout.write很多东西.在[supervisord]的AUTO子日志目录或[program:x]的stdout_logfile中都没有出现我想念什么吗?
I have a [program:x] running and it prints / sys.stdout.writes a lot of things. None of which comes up in either in the AUTO childlogdir of [supervisord] or in stdout_logfile of [program:x]Am I missing something?
如何捕获[program:x]中所有已打印或标准输出的内容?
How do I capture all that is printed or stdout-ed from [program:x] ?
在我的程序中,我明确地将两者都做
In my program I am explicitly doing both,
print "something"
sys.stdout.write("something")
相关的supervisord.conf文件
Relevant supervisord.conf file
[supervisord]
childlogdir = %(here)s/../logs/supervisord/
logfile = %(here)s/../logs/supervisord/supervisord.log
logfile_maxbytes = 100MB
logfile_backups = 10
loglevel = info
pidfile = %(here)s/../logs/supervisord/supervisord.pid
umask = 022
nodaemon = false
nocleanup = false
[program:x]
directory = %(here)s/../
command = python file.py
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile = /appropriate-path/to/access.log
推荐答案
Python输出被缓冲.在您supervisord.conf
中设置环境变量PYTHONUNBUFFERED=1
禁用缓冲并尽快显示日志消息:
Python output is buffered. Setting the environment variable PYTHONUNBUFFERED=1
in you supervisord.conf
will disable buffering and show log messages sooner:
[program:x]
environment = PYTHONUNBUFFERED=1
或添加 -u
命令行开关到python
命令:
or add the -u
command-line switch to python
command:
[program:x]
command = python -u file.py
或者,您可以显式刷新sys.stdout
处理程序:
Alternatively you can flush the sys.stdout
handler explicitly:
sys.stdout.flush()
在python 3.3及更高版本上,您可以添加flush=True
参数以使函数为您执行此操作:
On python 3.3 and up, you can add the flush=True
parameter to have the function do this for you:
print(something, flush=True)
这篇关于监督日志不显示我的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!