title: Empty logging with Django, Nginx, Gunicorn and supervisor
body: <p>I have a problem with my django logging in my production environment. I am using Nginx+Gunicorn+Supervisorctl to run my Django website. I have tried almost everything for two days without any result.</p>
  
  <p>My idea is to have two log files as I have defined in my Django app. One to store all log records (messages.log) and the other to store WARNING, ERROR and CRITICAL log records (errors.log)</p>
  
  <pre><code>LOGGING = {
  'version': 1,
  'disable_existing_loggers': True,
  'formatters': {
      'verbose': {
          'format': ' [%(asctime)s] [%(levelname)s] [%(name)s] %(message)s'
      },
      'simple': {
          'format': ' %(levelname)s %(message)s'
      },
  },
  'handlers': {
      'console': {
          'level': 'DEBUG',
          'class': 'logging.StreamHandler',
          'formatter': 'verbose'
      },
      'file': {
          'level': 'DEBUG',
          'class': 'logging.FileHandler',
          'formatter': 'verbose',
          'filename': '/home/myuser/logs/messages.log'
      },
      'file_errors': {
          'level': 'WARNING',
          'class': 'logging.FileHandler',
          'formatter': 'verbose',
          'filename': '/home/myuser/logs/errors.log'
      },
      'mail_admins': {
          'level': 'ERROR',
          'class': 'django.utils.log.AdminEmailHandler',
          'include_html': True
      }
  },
  'loggers': {
      'main': {
          'handlers': ['console', 'file', 'file_errors', 'mail_admins'],
          'level': 'DEBUG'
      },
      'caching': {
          'handlers': ['console', 'file', 'file_errors'],
          'level': 'DEBUG'
      }
  }
  </code></pre>
  
  <p>With this logging configuration, I am registering log records in my django app with commands like follows:</p>
  
  <pre><code>logger = logging.getLogger("main")
  logger.info("INFO message")
  logger.critical("CRITICAL message")
  </code></pre>
  
  <p>This commands are registered well in messages.log and errors.log in my development environment. Now, time to upload the app to production.</p>
  
  <p>In production I am running gunicorn with supervisor. This is my configuration to run gunicorn using supervisor:</p>
  
  <pre><code>[program:gunicorn_app]
  command=gunicorn --bind 172.31.19.71:8000 -c /home/myuser/app/gunicorn.conf.py -p /home/myuser/app/gunicorn.pid wsgi:application
  directory=/home/myuser/app
  user=myuser
  autostart=true
  stdout_logfile = /home/myuser/logs/app_supervisor
  stderr_logfile = /home/myuser/logs/app_error_supervisor
  autorestart=true
  redirect_stderr=true
  </code></pre>
  
  <p>As you can see, I am using a config file for gunicorn which content is as follows:</p>
  
  <pre><code>from __future__ import unicode_literals 
  import multiprocessing
  
  bind = "unix:%(proj_path)s/gunicorn.sock"
  workers = 4
  proc_name = "app_proc"
  </code></pre>
  
  <p>Finally Nginx is configured as follows:</p>
  
  <pre><code>server {
  
      listen 80;
      server_name www.myapp.com;
      client_max_body_size 10M;
      keepalive_timeout    15;
      error_log /home/myser/logs/app_error_nginx.log info;
  
      ...
  }
  </code></pre>
  
  <p>When I run my application the only log file generated is <strong>/home/myuser/logs/app_supervisor</strong>, which is the one generated by supervisor and only containing information about the process starting up.
  It is the only file contained in /home/myuser/logs.</p>
  
  <p>However, HTTP requests are displayed on <strong>/var/log/nginx/access.log</strong> but even /var/log/nginx/errors.log does not display any error or warning message coming from my app. </p>
  
  <p>Any idea? </p>