Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

supervisord logs don't show my output

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?

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")  

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 
like image 336
zubinmehta Avatar asked Dec 18 '12 14:12

zubinmehta


People also ask

How do I check supervisord logs?

The path to the activity log is configured via the logfile parameter in the [supervisord] section of the configuration file, defaulting to $CWD/supervisord. log. If the value of this option is the special string syslog, the activity log will be routed to the syslog service instead of being written to a file.

How do I start as a supervisor?

To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor.


2 Answers

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 

or add the -u command-line switch to python command:

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

Alternatively you can flush the sys.stdout handler explicitly:

sys.stdout.flush() 

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) 
like image 98
Martijn Pieters Avatar answered Sep 30 '22 02:09

Martijn Pieters


You can run your program like this:

python -u file.py 

this will produce unbuffered output

like image 44
Dmitry Belaventsev Avatar answered Sep 30 '22 02:09

Dmitry Belaventsev