Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django and fcgi - logging question

I have a site running in Django. Frontend is lighttpd and is using fcgi to host django.

I start my fcgi processes as follows:

python2.6 /<snip>/manage.py runfcgi maxrequests=10 host=127.0.0.1 port=8000 pidfile=django.pid

For logging, I have a RotatingFileHandler defined as follows:

file_handler = RotatingFileHandler(filename, maxBytes=10*1024*1024, backupCount=5,encoding='utf-8')

The logging is working. However, it looks like the files are rotating when they do not even get up to 10Kb, let alone 10Mb. My guess is that each fcgi instance is only handling 10 requests, and then re-spawning. Each respawn of fcgi creates a new file. I confirm that fcgi is starting up under new process id every so often (hard to tell time exactly, but under a minute).

Is there any way to get around this issues? I would like all fcgi instances logging to one file until it reaches the size limit, at which point a log file rotation would take place.

like image 740
Krystian Cybulski Avatar asked Jul 30 '09 00:07

Krystian Cybulski


1 Answers

As Alex stated, logging is thread-safe, but the standard handlers cannot be safely used to log from multiple processes into a single file.

ConcurrentLogHandler uses file locking to allow for logging from within multiple processes.

like image 93
gabor Avatar answered Sep 22 '22 13:09

gabor