title: Output colored logs from django through supervisor and docker-compose
body: <p>My objective is to get <strong>colorized</strong> logs of my <strong>Django</strong> webservice in <strong>docker-compose logs</strong>.</p>
  
  <ol>
  <li><p>I use docker-compose to manage a list of web services based on Django framework.</p></li>
  <li><p>Each container, run a <em>my_init</em> bash script, which in turn run a <em>runit</em> (this is historic in my case) script which runs a <em>supervisord</em> process:</p>
  
  <pre><code>my_init---runsvdir-+-runsv---run---supervisord-+-gunicorn---gunicorn
                     |                           |-nginx---8*[nginx]
                     |                           |-python---9*[python]
                     |                           |-python---python  (Django)
                     |                           `-redis-server---2*[{redis-server}]
                     `-runsv
  </code></pre></li>
  <li><p>The Django server is interfaced in WSGI with a <strong>Gunicorn</strong>, and served through a <strong>Nginx</strong></p></li>
  <li><p>The supervisord conf is the following:</p>
  
  <pre><code>[supervisord]
  http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)
  stdout_logfile=/dev/stdout
  stdout_logfile_maxbytes=0
  stderr_logfile=/dev/stderr
  stderr_logfile_maxbytes=0
  
  [program:gunicorn_core_service]
  #environment=myapp_VENV=/opt/myapp/venv/
  environment=PYTHONPATH=/opt/myapp/myappServer/myappServer
  command = /opt/myapp/venv/bin/gunicorn wsgi -b 0.0.0.0:8000 --timeout 90 --access-logfile /dev/stdout --error-logfile /dev/stderr
  directory = /opt/myapp/myappServer
  user = root
  autostart=true
  autorestart=true
  redirect_stderr=true
  stdout_logfile=/dev/stdout
  stdout_logfile_maxbytes=0
  stderr_logfile=/dev/stderr
  stderr_logfile_maxbytes=0
  
  [program:django-celery]
  command=/opt/myapp/venv/bin/python ./manage.py celery --app=myappServer.celeryapp:app worker -B --loglevel=INFO
  directory=/opt/myapp/myappServer
  numprocs=1
  stdout_logfile=/dev/stdout
  stdout_logfile_maxbytes=0
  stderr_logfile=/dev/stderr
  stderr_logfile_maxbytes=0
  redirect_stderr=true
  autostart=true
  autorestart=true
  startsecs=10
  
  [program:nginx]
  command=nginx -g "daemon off;"
  #user = root
  autostart=true
  autorestart=true
  redirect_stderr=true
  stdout_logfile=/dev/stdout
  stdout_logfile_maxbytes=0
  stderr_logfile=/dev/stderr
  stderr_logfile_maxbytes=0
  </code></pre></li>
  <li><p>Since docker can only log once process, the logs of all the process of my container are forwarded to <strong>/dev/stdout</strong> and <strong>/dev/stderr</strong></p></li>
  <li><p>And I use <a href="https://pypi.python.org/pypi/colorlog">colorlog</a> as color formatter to colorize Django logs:</p>
  
  <pre><code>'formatters': {
      'color': {
          '()': 'colorlog.ColoredFormatter',
          'format': '%(log_color)s%(levelname)-8s %(message)s',
          'log_colors': {
              'DEBUG':    'bold_black',
              'INFO':     'white',
              'WARNING':  'yellow',
              'ERROR':    'red',
              'CRITICAL': 'bold_red',
          },
      }
  },
  </code></pre>
  
  <ul>
  <li>When I run the service from inside the container <pre>./manage.py runserver</pre> the logs are colorized.</li>
  <li>However from outside, the docker-compose logs are not colorized.</li>
  </ul></li>
  </ol>
  
  <p>I tried to add <pre>tty: true</pre> in my services as described <a href="https://github.com/docker/compose/issues/2231">here</a>, but it seems it doesn\'t work anymore.</p>
  
  <p>Any idea?</p>