6

The official nginx docker image (Dockerfile) uses the following trick to hand off its logs to stdout and stderr so that they are captured by the docker log collector and viewable using docker logs <container-name>:

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log

I want to do the same, however I have supervisord as PID 1 in my container and it supervises the nginx process and captures stdout and stderr and puts it in it's own log file. Therefore the logs do not reach the docker log collector.

Here is the relevant block in my supervisord.conf

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
priority=990
; NOTE: We do not want to redirect stdout and stderr of a nginx process to a logfile because we want docker log collector to get them.
stdout_logfile= NOT SURE WHAT TO PUT HERE?
stderr_logfile= NOT SURE WHAT TO PUT HERE?
username=www-data
autorestart=true

The supervisord docs are great (http://supervisord.org/configuration.html) but for stdout_logfile they don't give me the answer I need - namely, how do I configure supervisord to not intercept a processes stdout / stderr ( or to capture to a log file but also forward to normal stdout / stderr).

What I tried already:

  1. stdout_logfile=NONE - Get no logs neither stdout or to a file
  2. stdout_logfile=/var/log/supervisor/%(program_name)s.log - Get logs to a file but not stdout.
  3. Not defining stdout_logfile - Get logs to a randomly named file but not stdout.
  4. stdout_logfile=/dev/stdout - Supervisord gives a error:

    CRIT uncaptured python exception, closing channel (stdout)> (:[Errno 29] Illegal seek [/usr/lib/python2.7/dist-packages/supervisor/supervisord.py|runforever|233] [/usr/lib/python2.7/dist-packages/supervisor/dispatchers.py|handle_read_event|231] [/usr/lib/python2.7/dist-packages/supervisor/dispatchers.py|record_output|165] [/usr/lib/python2.7/dist-packages/supervisor/dispatchers.py|_log|141] [/usr/lib/python2.7/dist-packages/supervisor/loggers.py|info|273] [/usr/lib/python2.7/dist-packages/supervisor/loggers.py|log|291] [/usr/lib/python2.7/dist-packages/supervisor/loggers.py|emit|186] [/usr/lib/python2.7/dist-packages/supervisor/loggers.py|doRollover|195])

9

The Illegal seek error is caused by the code in supervisord that is responsible for log file rotation. To redirect to stdout/stderr you have to disable log file rotation, as explained here:

http://veithen.github.io/2015/01/08/supervisord-redirecting-stdout.html

  • Thank you very much, using stdout_logfile=/dev/stdout along with stdout_logfile_maxbytes=0 solved my problem. – Tom Jan 9 '15 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.