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:

[program:myapp]
command=/usr/bin/python -u myapp.py
stdout_logfile=/var/log/supervisor/myapp.log
autorestart=unexpected
redirect_stderr=true