当使用RotatingFileHandler作为django的日志处理器的时候,会报:
Traceback (most recent call last):
File "C:\Python27\lib\logging\handlers.py", line 78, in emit
self.doRollover()
File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover
os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process
原因是:在开发模式下,通过python manage.py runserver的方式启动django的时候,会启动两个线程去加载settings文件,一个是用来给你服务的,另一个是监控settings文件是否改变的,如果改变就立即让他生效,所以会导致上面的错误,解决方法是加上--noreload参数。
python manage.py runserver --noreload
参见老外的日志:
http://azaleasays.com/2014/05/01/django-logging-with-rotatingfilehandler-error/