[Python-Dev] PEP282 and the warnings framework

holger krekel pyth@devel.trillke.net
Thu, 16 May 2002 03:48:24 +0200


Kevin Butler wrote:
> I don't see how it would work without drastically increasing the configuration 
> complexity.
> 
> 	log = logging.getLogger( "pil.image.gif" )
> 	log.log( IOError( reason ))
> Currently, I can configure the hierachy pil...image...gif, and I can specify 
> the integer priority level below which I won't log a message in that category.
> 
> If you add the hierarchy 
> IOError...EnvironmentError...StandardError...Exception, how do you decide 
> whether to log the message or not?

e.g.
    log.warn(IOError(...))
    log.err(IOError(...))
            
note that Exceptions would *not* be a Message but 
the constructor of a DebugMessage/WarnMessage should accept an exception.

i still don't think that the functionality of the logger-hierarchy
would be compromised or more difficult to configure. I do think though
that giving 'type-based' filtering precedence over integer-comparisons
makes sense.

> If I have a choice between writing:
> 
>    log.debug(
>      "HOME environment variable set to non-existent directory %s",
>      homedir
>      )

with the mapping in my previous posting you would write

    log.debug(
        "HOME environment variable set to non-existent directory " + homedir
        )

but if you app grows you might prefer

    log.debug(EnvMessage('HOME','points to non-existent directory'))

and have EnvMessage handle any environment problems report systematically
and well encapsulated.
        
> I'm most likely to just use the string option - and
> if I don't have a 'ConfigurationException' class & constructor that exactly
> matches what I need, I'm even more likely to just log the string.

i use strings often for ad-hoc coding. heck, i even like debugging with 
'print' if possible.  But there comes a point where you you want to log 
more and typed information and more intelligently and conveniently.
Having to write '%s' in a logging call is not convenient IMO.

> And you can get /exactly/ the TraceStateMessage example, including formatting, by:
> 	#
> 	# TraceStateMessage class you defined	
> 	#
> 
> 	trace = logging.getLogger( "trace" )
> 	trace.debug( "%s", TraceStateMessage( obj ))

nice :-) But does this beat

    somelog.traceobj(obj)


People seem to apply their (logging) experience from the
java/c++ world to python not realizing how much easier it
is with python to work with objects. Were we to speak
in java terms i wouldn't bother to argue :-)

just my 2c,

    holger