title: Logging message in Django running through Apache
body: <p>I am running Ubuntu 14.04 on my notebook and I am using Django 1.6.4 (with virtualenv) together with Apache 2.4.7.</p>
  
  <p>I set up a site and want to log from my views some debugging information to my logfile called <code>homepage.log</code> (the name of my app is homepage). When I run my site with Django's built-in server all messages are shown in the logfile but when running with Apache no message lands in the file. My project is located under <code>/home/nick/Workspace/Web/kleyboldt_django/</code> (kleyboldt is the name of the guy I am writting for). There I have my wsgi file, my virtual environment called <code>env</code> and my actual project called <code>kleyboldt-homepage</code>. I would like to log in <code>kleyboldt_homepage/homepage.log</code>. My setup is:</p>
  
  <p><strong>/etc/apache2/sites-available/mks.conf</strong></p>
  
  <pre><code>WSGIDaemonProcess mks.com python-path=/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage:/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages
  WSGIProcessGroup mks.com
  
  &lt;VirtualHost *:80&gt;
      ...
      &lt;Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/static&gt;
          Require all granted
      &lt;/Directory&gt;
  
      &lt;Directory /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/static/media&gt;
          Require all granted
      &lt;/Directory&gt;
  
      WSGIScriptAlias / /home/nick/Workspace/Web/kleyboldt_django/kleyboldt.wsgi
  
      ServerName mks.com
  
      &lt;Directory /home/nick/Workspace/Web/kleyboldt_django/&gt;
          Require all granted
          Order allow,deny
          Allow from all
      &lt;/Directory&gt;
  
      &lt;Directory /home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/&gt;
          Require all granted
          Order allow,deny
          Allow from all
      &lt;/Directory&gt;
  
      ErrorLog /home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/homepage.log
      LogLevel debug
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong>/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/kleyboldt_homepage/settings.py</strong></p>
  
  <pre><code>...
  LOGGING = {
      'version': 1,
      'disable_existing_loggers': True,
      'formatters': {
          'verbose': {
              'format': '%(levelname)s %(asctime)s %(module)s:\t %(message)s',
              'datefmt': '%d/%B/%Y %H:%M:%S',
          },
          'simple': {
              'format': '%(levelname)s %(message)s',
          },
      },
      'handlers': {
          'null': {
              'level': 'DEBUG',
              'class': 'django.utils.log.NullHandler',
          },
          'console': {
              'level': 'DEBUG',
              'class': 'logging.StreamHandler',
  
  
    'formatter': 'simple',
      },
      'file': {
          'level': 'DEBUG',
          'class': 'logging.FileHandler',
          'filename': 'homepage.log',
          'formatter': 'verbose',
      }
  },
  'loggers': {
      'kleyboldt_homepage': {
          'handlers': ['console', 'file'],
          'level': 'DEBUG',
      },
  },
  </code></pre>
  
  <p>}</p>
  
  <p><strong>/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/homepage/views.py</strong></p>
  
  <pre><code>import logging
  
  logger = logging.getLogger('kleyboldt_homepage')
  
  def home(request):
      logger.warning("test")
      return render(request, 'homepage/home.html', {})
  </code></pre>
  
  <p>When running Apache the warning never appears.</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>I changed the logfile to <code>/tmp/homepage.log</code> but then Apache shows an error message telling me that a misconfiguration was discovered. Because I set the error log in my VirtualHost to my logfile for my homepage Apache dumped the error message in it.</p>
  
  <p><strong>/home/nick/Workspace/Web/kleyboldt_django/kleyboldt_homepage/homepage.log</strong></p>
  
  <pre><code>[Sat May 03 14:00:04.996997 2014] [authz_core:debug] [pid 16747] mod_authz_core.c(802): [client 127.0.0.1:47319] AH01626: authorization result of Require all granted: granted, referer: http://mks.com/
  [Sat May 03 14:00:04.997084 2014] [authz_core:debug] [pid 16747] mod_authz_core.c(802): [client 127.0.0.1:47319] AH01626: authorization result of &lt;RequireAny&gt;: granted, referer: http://mks.com/
  [Sat May 03 14:00:04.997272 2014] [authz_core:debug] [pid 16747] mod_authz_core.c(802): [client 127.0.0.1:47319] AH01626: authorization result of Require all granted: granted, referer: http://mks.com/
  [Sat May 03 14:00:04.997295 2014] [authz_core:debug] [pid 16747] mod_authz_core.c(802): [client 127.0.0.1:47319] AH01626: authorization result of &lt;RequireAny&gt;: granted, referer: http://mks.com/
  [Sat May 03 14:00:05.015130 2014] [:info] [pid 16746] [remote 127.0.0.1:36049] mod_wsgi (pid=16746, process='mks.com', application='mks.com|'): Loading WSGI script '/home/nick/Workspace/Web/kleyboldt_django/kleyboldt.wsgi'.
  [Sat May 03 14:00:05.187017 2014] [:error] [pid 16746] [remote 127.0.0.1:36049] mod_wsgi (pid=16746): Exception occurred processing WSGI script '/home/nick/Workspace/Web/kleyboldt_django/kleyboldt.wsgi'.
  [Sat May 03 14:00:05.187112 2014] [:error] [pid 16746] [remote 127.0.0.1:36049] Traceback (most recent call last):
  [Sat May 03 14:00:05.187145 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
  [Sat May 03 14:00:05.187282 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     self.load_middleware()
  [Sat May 03 14:00:05.187329 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 46, in load_middleware
  [Sat May 03 14:00:05.187481 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     for middleware_path in settings.MIDDLEWARE_CLASSES:
  [Sat May 03 14:00:05.187542 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
  [Sat May 03 14:00:05.187652 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     self._setup(name)
  [Sat May 03 14:00:05.187710 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/django/conf/__init__.py", line 50, in _setup
  [Sat May 03 14:00:05.187746 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     self._configure_logging()
  [Sat May 03 14:00:05.187793 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/home/nick/Workspace/Web/kleyboldt_django/env/lib/python2.7/site-packages/django/conf/__init__.py", line 80, in _configure_logging
  [Sat May 03 14:00:05.187827 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     logging_config_func(self.LOGGING)
  [Sat May 03 14:00:05.187887 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/usr/lib/python2.7/logging/config.py", line 794, in dictConfig
  [Sat May 03 14:00:05.188141 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     dictConfigClass(config).configure()
  [Sat May 03 14:00:05.188182 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]   File "/usr/lib/python2.7/logging/config.py", line 576, in configure
  [Sat May 03 14:00:05.188218 2014] [:error] [pid 16746] [remote 127.0.0.1:36049]     '%r: %s' % (name, e))
  [Sat May 03 14:00:05.188255 2014] [:error] [pid 16746] [remote 127.0.0.1:36049] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/tmp/homepage.log'
  </code></pre>
  
  <p>Obviously Apache does not have the permissions to write to this file. Therefore I changed the group of <code>/tmp/homepage.log</code> to <code>www</code>. Now writting debug messages to this file works. Now I changed the group of <code>homepage.log</code> in my project also to <code>www</code>. Unfortunately it does not work. The error log shows that Apache does not have permissions to write in my project folder. What should I change?</p>