Patches item #1598415, was opened at 2006-11-17 09:44 Message generated for change (Comment added) made by cjschr You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1598415&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Modules Group: Python 2.5 >Status: Open Resolution: Fixed Priority: 5 Private: No Submitted By: chads (cjschr) Assigned to: Vinay Sajip (vsajip) Summary: Logging Module - followfile patch Initial Comment: Pertaining to the FileHandler and the file being written to: It's possible that the file being written to will be rolled-over by an external application such as newsyslog. By default, FileHandler tracks the file descriptor, not the file. If the original file is renamed, the file descriptor is still updated; however, it's probably desired that continued updates to the original file take place instead. This patch adds an attribute to the FileHandler class constructor (and basicConfig kw as well). If the attribute evaluates to True, the filename, not the descriptor is tracked. Basically, the code compares the file status from a previous emit call to the current call before the base class emit is called. If a difference in st_ino or st_dev is found, the current stream is flush/closed and a new one, based on baseFilename, is created, file status is updated, and then the base class emit is called. ---------------------------------------------------------------------- >Comment By: chads (cjschr) Date: 2007-01-15 09:43 Message: Logged In: YES user_id=1093928 Originator: YES I like the implementation Vinay. Nice work. Thx ---------------------------------------------------------------------- Comment By: Vinay Sajip (vsajip) Date: 2007-01-14 15:57 Message: Logged In: YES user_id=308438 Originator: NO WatchedFileHandler added to logging.handlers, checked into trunk. Documentation updated, too. ---------------------------------------------------------------------- Comment By: Vinay Sajip (vsajip) Date: 2007-01-11 15:50 Message: Logged In: YES user_id=308438 Originator: NO I've had a bit more of a think about this, and realised that I made a boo-boo in one of my earlier comments. Under Windows, log files are opened with exclusive locks, so that other processes cannot rename or move files which are open. So I believe the approach won't work at all under Windows. (Chad, sorry about making you redo the patch with ST_SIZE rather than ST_DEV and ST_INO). I also think this is a less common use case than warrants supporting it at the basicConfig() level, which is for really very basic usage configuration. So I would advocate adding a WatchedFileHandler (in logging.handlers) which watches st_dev and st_ino (as per Chad's original patch) and closes the old file descriptor and reopens the file when a change is seen. Some recent changes checked into SVN trunk facilitate the reopening - I've added an _open() method to FileHandler to do this. Chad, what do you think of this approach? ---------------------------------------------------------------------- Comment By: chads (cjschr) Date: 2006-11-20 11:06 Message: Logged In: YES user_id=1093928 Originator: YES Uploaded the wrong diff. This is the correct one. ---------------------------------------------------------------------- Comment By: chads (cjschr) Date: 2006-11-20 11:02 Message: Logged In: YES user_id=1093928 Originator: YES Updated per vsajip to work on Windoze too. The code now checks for a current size < previous size (based on ST_SIZE). ---------------------------------------------------------------------- Comment By: Vinay Sajip (vsajip) Date: 2006-11-19 14:32 Message: Logged In: YES user_id=308438 Originator: NO This patch, relying as it does on Unix-specific details such as i-nodes, does not appear as if it will work under Windows. For that reason I will mark it as Pending and Invalid for now, if cjschr can update this tracker item with how the patch will work on Windows, I will look at it further. The SF system will automatically close it if no update is made to the item in approx. 2 weeks, though it can still be reopened after that. ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2006-11-18 13:14 Message: Logged In: YES user_id=849994 Originator: NO Assigning to Vinay. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1598415&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches