Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to log to a single file with concurrent processes in Django without exclusive locks
    text
    copied!<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="nofollow">this sample project</a>, I've trying using <a href="https://pypi.python.org/pypi/ConcurrentLogHandler" rel="nofollow">ConcurrentLogHandler</a> like this:</p> <p>in <a href="https://github.com/fernandoacorreia/DjangoWAWSLogging/blob/master/DjangoWAWSLogging/DjangoWAWSLogging/settings.py" rel="nofollow">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="nofollow">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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload