This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cdleary
Recipients
Date 2007-08-01.08:14:34
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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
History
Date User Action Args
2007-08-23 15:59:30adminlinkissue1765140 messages
2007-08-23 15:59:30admincreate