supervisor 捕获 print 的输出到 log 文件中

If you are also using Supervisor to monitor and heal your long running Python projects and observed that output of your program is not being logged to stdout_logfile, it is because Python print statement does not automatically flush output to STDOUT.

One solution is using sys.stdout.flush() frequently to flush the output or if you are using Python 3.3, print(msg, flush=True) is another solution. However, a better solution is to run python with -u parameter (unbuffered mode). Alternatively, you can set PYTHONUNBUFFERED environment variable for this.

Here’s an example configuration for supervisord.conf:

command=/usr/bin/python -u