[Patches] [ python-Patches-1598415 ] Logging Module - followfile patch

SourceForge.net noreply at sourceforge.net
Mon Jan 15 17:29:21 CET 2007


Patches item #1598415, was opened at 2006-11-17 15:44
Message generated for change (Comment added) made by vsajip
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: Closed
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: Vinay Sajip (vsajip)
Date: 2007-01-15 16:29

Message:
Logged In: YES 
user_id=308438
Originator: NO

You're welcome, Chad. Thanks for the idea. Closing this item.

----------------------------------------------------------------------

Comment By: chads (cjschr)
Date: 2007-01-15 15: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 21: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 21: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 17: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 17: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 20: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 19: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


More information about the Patches mailing list