title: Why is my gunicorn process ignoring the log-level setting with Django?
body: <p>I have Nginx, Gunicorn, and Django all running on the same Ubuntu EC2 instance. I have a fairly conventional setup and would like to log all gunicorn errors to a particular file.</p>
  
  <p>My configuration for Gunicorn is:</p>
  
  <pre><code>#!/bin/bash
  
  NAME="server"
  GUNICORNDIR=/ebs/env/bin
  DJANGODIR=/ebs/server/
  SOCKFILE=/tmp/gunicorn.sock
  LOGFILE=/var/log/gunicorn/gunicorn.error
  USER=ubuntu
  GROUP=ubuntu
  NUM_WORKERS=5
  TIMEOUT=60
  DJANGO_SETTINGS_MODULE=settings
  DJANGO_WSGI_MODULE=wsgi
  
  echo "Starting $NAME"
  
  RUNDIR=$(dirname $SOCKFILE)
  test -d $RUNDIR || mkdir -p $RUNDIR
  
  exec $GUNICORNDIR/gunicorn ${DJANGO_WSGI_MODULE}:application \
    --name $NAME \
    --workers $NUM_WORKERS \
    --timeout=$TIMEOUT \
    --user=$USER --group=$GROUP \
    --log-level=error --log-file=$LOGFILE \
    --bind=unix:$SOCKFILE
  </code></pre>
  
  <p>However with this configuration I am getting all logs from DEBUG and above written to the file. My log-level parameter appears to be getting ignored.</p>
  
  <p>What I am looking for is to only have these types of log messages written:</p>
  
  <pre><code>2014-01-02 13:54:53 [3327] [CRITICAL] WORKER TIMEOUT (pid:3338)
  2014-01-02 13:54:53 [3327] [CRITICAL] WORKER TIMEOUT (pid:3338)
  </code></pre>
  
  <p>I thought that the Django logging config specified in my settings.py might be interfering so I added a handler and a logger to try and target gunicorn but that did not work.</p>
  
  <pre><code>'handlers': {
  'gunicorn': {
      'level': 'ERROR',
      'class': 'logging.handlers.RotatingFileHandler',
      'formatter': 'verbose',
      'filename': '/ebs/log/gunicorn.error',
      'maxBytes': 1024 * 1024 * 100,
  },
  }
  'loggers': {
  'gunicorn.errors': {
  'level': 'ERROR',
  'handlers': ['gunicorn'],
  'propagate': False,
  },
  </code></pre>
  
  <p>Here are the versions that I am running</p>
  
  <p>Django 1.5.4
  Nginx nginx/1.1.19
  Gunicorn 18.0</p>
  
  <p>Any thoughts on what is wrong here?</p>
  
  <p>** Update **</p>
  
  <p>Here is what my django logging config looks like:</p>
  
  <pre><code>LOGGING = {
  'version': 1,
  'disable_existing_loggers': True,
  'root': {
      'level': 'WARNING',
      'handlers': ['sentry'],
  },
  'formatters': {
      'verbose': {
          'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
      },
      'simple': {
          'format': '%(levelname)s %(asctime)s -- %(message)s'
      }
  },
  'handlers': {
      'sentry': {
          'level': 'ERROR',
          'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
      },
      'sentry_file': {
          'level': 'ERROR',
          'class': 'logging.handlers.RotatingFileHandler',
          'formatter': 'verbose',
          'filename': '/ebs/log/sentry_log.txt',
          'maxBytes': 1024 * 1024 * 100,  # 100 mb
      },
      'celery': {
          'level': 'DEBUG',
          'class': 'logging.handlers.RotatingFileHandler',
          'filename': '/ebs/log/celery/celery.log',
          'formatter': 'verbose',
          'maxBytes': 1024 * 1024 * 100,
      },
      'apps': {
          'level': 'DEBUG',
          'class': 'logging.handlers.RotatingFileHandler',
          'formatter': 'verbose',
          'filename': '/ebs/log/apps.log',
          'maxBytes': 1024 * 1024 * 100,
      },
      'apps.dss': {
          'level': 'DEBUG',
          'class': 'logging.handlers.RotatingFileHandler',
          'formatter': 'verbose',
          'filename': '/ebs/log/dss_apps.log',
          'maxBytes': 1024 * 1024 * 100,
      },
  
  },
  'loggers': {
      'django.db.backends': {
          'level': 'DEBUG',
          'handlers': ['sentry'],
          'propagate': False,
      },
      'sentry': {
          'level': 'DEBUG',
          'handlers': ['sentry'],
          'propagate': False,
      },
      'sentry.errors': {
          'level': 'ERROR',
          'handlers': ['sentry_file', 'sentry'],
          'propagate': False,
      },
      'celery': {
          'level': 'INFO',
          'handlers': ['sentry', 'celery'],
          'propagate': False
      },
      'apps': {
          'level': 'DEBUG',
          'handlers': ['apps', 'sentry'],
          'propagate': False
      },
      'apps.dss' : {
          'level': 'DEBUG',
          'handlers': ['apps.dss', 'sentry'],
          'propagate': False,
      },
  },
  }
  </code></pre>