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/348 github. com/openstack/ glance/ commit/ 20f09f6bd589613 043e5b1eba70aa3 8bb63746b4
Committed: http://
Submitter: Jenkins
Branch: milestone-proposed
status fixcommitted
done
commit 20f09f6bd589613 043e5b1eba70aa3 8bb63746b4
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