zub*_*hta 22 python logging supervisord
我有一个[program:x]正在运行,它打印/ sys.stdout.writes很多东西.在[supervisord]的AUTO childlogdir或[program:x]的stdout_logfile中都没有出现这些内容我错过了什么?
如何从[program:x]中捕获所有打印或stdout-ed的内容?
在我的程序中,我明确地做了两个,
print "something"
sys.stdout.write("something")
Run Code Online (Sandbox Code Playgroud)
相关的supervisord.conf文件
[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
Run Code Online (Sandbox Code Playgroud)
Mar*_*ers 33
Python输出是缓冲的.在您中设置环境变量PYTHONUNBUFFERED=1supervisord.conf将禁用缓冲并更快地显示日志消息:
[program:x]
environment = PYTHONUNBUFFERED=1
Run Code Online (Sandbox Code Playgroud)
或者将-u命令行开关添加到python命令:
[program:x]
command = python -u file.py
Run Code Online (Sandbox Code Playgroud)
或者,您可以sys.stdout显式刷新处理程序:
sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)
在python 3.3及更高版本中,您可以添加flush=True参数以使该功能为您执行此操作:
print(something, flush=True)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15264 次 |
| 最近记录: |