[Python-Dev] PEP282 and the warnings framework
Kevin Butler
kbutler@campuspipeline.com
Wed, 15 May 2002 12:53:09 -0600
holger krekel wrote:
> Kevin Butler wrote:
>
>>In contrast, creating a new Logger (or "Category") instance meets little
>>resistance, and a shift to that model was welcomed by all...except the
>>developer of the message hierarchy logging system.
>
>
> having a Logger-instance which processes messages is quite orthogonal
> to how the messages are categorized.
...
> Where is the advantage if you use integer log levels?
> Am i missing something?
I think you're missing something. The proposed API (PEP 282) provides integer
priorities (log/error/debug/etc.), and hierarchical categorization by the
"logger" instance.
The logger instance contains the category (I forget if we call Logger
constructors or call a factory method):
logger = Logger( "pil.image.jpeg" )
logger2 = Logger( "pil.image.gif" )
logger.debug( "My JPEG Image PIL Debug message" )
logger2.error( "My GIF image PIL error message" )
The logging of theses message is configurable based on the "pil" category, the
"pil.image" category, the "pil.image.jpeg"/"pil.image.gif" category, and their
priority.
This means if I am debugging something in PIL images, I can enable all log
messages in the "image" category. Or I could enable just everything having to
do with JPEG images, and ignore all that proprietary GIF stuff.
To get similar functionality with a message-based hierarchy, I'd have to
define separate "PilImageJpegMessage" and "PilImageGifMessage" classes, and
have them both extend a PilImageMessage class.
> (The base Message class should accept Exceptions and Strings IMO.)
FWIW, once you allow logging 'string'-type messages, most logged messages will
be a string (especially debug messages), because it is much easier than
creating an instance of some other clsas. Thus, if your categorization is
based on the class of the logged message, the "string" category gets very large...
> This doesn't touch the question how messages
> should be categorized (by integer or by class-type).
The question, as I understood it, was whether to categorize by
message-class-name, or by logger-instance-category.
Although the 'message-class' hierarchy appears attractive, logger-instance
categorization has been more useful to me.
kb