title: How to log to a single file with concurrent processes in Django without exclusive locks
body: <p>Given a Django application that is being executed concurrently on multiple servers, how can this application log to a single shared log file (in a network share), without keeping this file permanently open in exclusive mode?</p>
  
  <p>This situation applies to Django applications hosted on Windows Azure Websites when you want to take advantage of log streaming.</p>
  
  <p>On <a href="https://github.com/fernandoacorreia/DjangoWAWSLogging" rel="noreferrer">this sample project</a>, I've trying using <a href="https://pypi.python.org/pypi/ConcurrentLogHandler" rel="noreferrer">ConcurrentLogHandler</a> like this:</p>
  
  <p>in <a href="https://github.com/fernandoacorreia/DjangoWAWSLogging/blob/master/DjangoWAWSLogging/DjangoWAWSLogging/settings.py" rel="noreferrer">settings.py</a>:</p>
  
  <pre><code>'ConcurrentLogHandler':{
      'level': 'DEBUG',
      'class': 'cloghandler.ConcurrentRotatingFileHandler',
      'formatter': 'verbose',
      'filename': os.getenv('LOGFILE', 'django.log')
  },
  </code></pre>
  
  <p>in <a href="https://github.com/fernandoacorreia/DjangoWAWSLogging/blob/master/DjangoWAWSLogging/DjangoWAWSLogging/views.py" rel="noreferrer">views.py</a>:</p>
  
  <pre><code>from time import gmtime, strftime
  import logging
  from django.http import HttpResponse
  
  logger = logging.getLogger(__name__)
  
  def home(request):
      current_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
      logger.info('home ' + current_time)
      return HttpResponse("Hello from Django! It is now " + current_time + ".\n")
  </code></pre>
  
  <p>The logs are written but the file doesn't seem to be flushed while the website is running. Also, if I try to read the file using FTP I get this message: "550 The process cannot access the file because it is being used by another process."</p>
  
  <p>If I stop the application, the file is closed and I can read the file and see all the logs in it.</p>
  
  <p>I assume that ConcurrentLogHandler would allow shared access to the log file. Is this assumption wrong? Is there some additional configuration needed? Is there an alternative?</p>