Patches item #1765140, was opened at 2007-08-01 08:14
Message generated for change (Settings changed) made by cdleary
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1765140&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: Library (Lib)
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Chris Leary (cdleary)
>Assigned to: Vinay Sajip (vsajip)
Summary: logging: delay_fh option and configuration kwargs

Initial Comment:
Streams (read: files) are opened in potentially destructive modes when loading 
logging configurations. This patch provides library users with a method of 
postponing the opening of streams. The method is simple, powerful, and should 
be fully compatible with existing infrastructure.

The StreamHandler now allows a callback function to be passed as an 
initialization parameter (@param strm). This function must be callable with no 
arguments and return a valid stream. A function passed in this manner can be 
initialized via the initialize_stream() method call; however, if the user 
chooses not to call initialize_stream() explicitly, the stream is initialized 
on the first attempt to emit a record.

To take advantage of this ability, the FileHandler has been extended with 
callback-passing functionality. If the delay_fh initialization parameter is 
asserted, a file-opening closure is passed to the StreamHandler (superclass) 
initialization method.

This ability has also been extended to the module's fileConfig() function. 
Though fileConfig()'s optional delay_fh parameter, the user may load a 
configuration from file without undesired file handle opening effects. This is 
particularly useful when running many instances of the same program on a single 
file system -- the user now has the ability to change (at runtime) FileHandlers 
that would otherwise be opened in 'w' mode, clobbering the other 
instantiation's logs.

Another, seemingly tangential portion of the patch adds a kwargs specifier to 
the configuration file. This is to add the flexibility of adding a delay_fh 
keyword indicator without specifying other arguments unnecessarily as part of 
'args'. It still follows the 1.5 compatible apply() syntax, and it only takes 
another 4 lines ;)

Implementation Notes:
- Tested in regtest and with an application I wrote that's quite 
logging-intensive, and both check out OK so far.
- I broke some functions I was working on into helpers for readability, as they 
were getting too long. They're all initialization functions that shouldn't be 
performance critical.
- Private functions that I added weren't given default values for the delay_fh 
parameter, since nobody knows about them; however, I gave the private functions 
that were already there a default value for the delay_fh parameter just to be 
extra safe and backwards compatible. Hopefully nobody's using those anyway.
- I tried my best to follow existing style -- feel free to yell at me if I 
missed it somewhere :D

- Chris Leary

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1765140&group_id=5470
_______________________________________________
Patches mailing list
Patches@python.org
http://mail.python.org/mailman/listinfo/patches

Reply via email to