简体   繁体   English

supervisord日志不显示我的输出

[英]supervisord logs don't show my output

I have a [program:x] running and it prints / sys.stdout.writes a lot of things. 我有一个[program:x]正在运行,它打印/ sys.stdout.writes很多东西。 None of which comes up in either in the AUTO childlogdir of [supervisord] or in stdout_logfile of [program:x] Am I missing something? 在[supervisord]的AUTO childlogdir或[program:x]的stdout_logfile中都没有出现这些内容我错过了什么?

How do I capture all that is printed or stdout-ed from [program:x] ? 如何从[program:x]中捕获所有打印或stdout-ed的内容?

In my program I am explicitly doing both, 在我的程序中,我明确地做了两个,

print "something"
sys.stdout.write("something") 

Relevant supervisord.conf file 相关的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

You can run your program like this: 您可以像这样运行您的程序:

python -u file.py

this will produce unbuffered output 这将产生无缓冲的输出

Python output is buffered. Python输出是缓冲的。 Setting the environment variable PYTHONUNBUFFERED=1 in you supervisord.conf will disable buffering and show log messages sooner: 设置环境变量PYTHONUNBUFFERED=1supervisord.conf迟早会禁用缓冲和显示日志消息:

[program:x]
environment = PYTHONUNBUFFERED=1

or add the -u command-line switch to python command: 或者将-u命令行开关添加到python命令:

[program:x]
command = python -u file.py

Alternatively you can flush the sys.stdout handler explicitly: 或者,您可以显式刷新sys.stdout处理程序:

sys.stdout.flush()

On python 3.3 and up, you can add the flush=True parameter to have the function do this for you: 在python 3.3及更高版本中,您可以添加flush=True参数以使该函数为您执行此操作:

print(something, flush=True)

If you have python based script that you can't or don't want to change to flush output on a regular base then you can use unbuffer from the Expect package. 如果您有基于python的脚本,您不能或不想更改为常规基础上的刷新输出,那么您可以使用Expect包中的unbuffer

For a Django application in a docker container I've lately used it like that (from a shell script run from supervisord): 对于docker容器中的Django应用程序,我最近使用它(来自从supervisord运行的shell脚本):

unbuffer python -u manage.py runserver 0.0.0.0:11000 2>&1 >> /var/log/django.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM