I'm running a django webapp in vagrant (running ubuntu) on a Windows machine. The app has a RotatingFileHandler set up, which is for the most part logging correctly. But eventually the log file fills up, at which point it fails to roll over
Logged from file util.py, line 79
Traceback (most recent call last):
File "/usr/lib/python2.7/logging/handlers.py", line 78, in emit
self.doRollover()
File "/usr/lib/python2.7/logging/handlers.py", line 141, in doRollover
os.rename(self.baseFilename, dfn)
OSError: [Errno 26] Text file busy
(many times over)
Here is the config snippet for the RotatingFileHandler:
'default': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': 'logs/application.log',
'maxBytes': 1024 * 1024 * 5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
The problem seems to be that it is logging in the shared vagrant directory, so it is running into Windows file locking issues. If I change it to logging in a directory outside of the shared directory it rolls over okay.
My question is, is there anything I can do to prevent the error above without having to move the logging out of the vagrant directory?
I'd like to keep it in there so that it is more easily portable to other servers and so I can view the logs in windows.
If you were running Django development server when you saw the error, try
python manage.py runserver --noreload
This is because by default, two processes of Django servers are running. One is the actual server, while the other is to detect changes in the code and reload the server. Therefore, settings.py is imported twice, and consequently the two processes are accessing the log file at the same time.
More details here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With