FileHandler opens the logfile at startup, keeps the stream open and
continues to log to it forever.
If logrotate decides to rotate the file, it will rename the original
file and a new file is created with the same attributes as the original
file.
The problem is that the process is still writing to the original file,
not the newly created file. Traditionally, system daemons respond to
a SIGHUP by re-opening log files and logrotate can be configured to
deliver this signal on rotation.
However, python has an elegant solution. WatchedFileHandler monitors
the inode for the specified log file name and, if that ever changes,
it re-opens the stream.
Nova already uses WatchedFileHandler to good effect. See:
Reviewed: https:/ /review. openstack. org/340 github. com/openstack/ glance/ commit/ ecbcc09ce5c337a 84d8adf19f95752 9c4f76a075
Committed: http://
Submitter: Jenkins
Branch: master
status fixcommitted
done
commit ecbcc09ce5c337a 84d8adf19f95752 9c4f76a075
Author: Mark McLoughlin <email address hidden>
Date: Thu Aug 25 12:20:51 2011 +0100
Switch file based logging to WatchedFileHandler for logrotate
Fixes lp:772397
FileHandler opens the logfile at startup, keeps the stream open and
continues to log to it forever.
If logrotate decides to rotate the file, it will rename the original
file and a new file is created with the same attributes as the original
file.
The problem is that the process is still writing to the original file,
not the newly created file. Traditionally, system daemons respond to
a SIGHUP by re-opening log files and logrotate can be configured to
deliver this signal on rotation.
However, python has an elegant solution. WatchedFileHandler monitors
the inode for the specified log file name and, if that ever changes,
it re-opens the stream.
Nova already uses WatchedFileHandler to good effect. See:
https:/ /code.launchpad .net/~soren/ nova/logrotate/ +merge/ 50292
Change-Id: I7f693f133d230d 65d7c94ebf3a2ec 0c8b362f993