[Python-Dev] Using logging in the stdlib and its unit tests

Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Dec 8 15:54:09 CET 2010

Antoine Pitrou <solipsis <at> pitrou.net> writes:

> I'm not talking specifically about exceptions, but about errors in
> general. If the case wasn't common, I'm not sure why the error() and
> critical() methods would exist at all.
> (of course I'm assuming error() is meant to output error messages. If
> that's a wrong interpretation then I'm a bit puzzled )

Then again, it's not always helpful when *library* code prints out messages to
stderr. A user of the library might prefer that an error code be returned or an
exception raised, so they can deal with the condition most appropriately.

> I was talking about the user of a library, not its developer (see the
> snippet quoted above).

Yes, but see my response to that. A user of a library doesn't need to know the
specifics of what loggers that library uses, they just need to make a positive
statement of where they want warning and error messages go, and how they want
them formatted.

BTW we haven't discussed this yet - but these enabled-by-default messages, what
format should they have? (e.g. just message, logger name + message, logger name
+ severity + message etc.) It might sound like a trivial point, but it also
seems like whatever you pick, some bikeshed discussions would ensue. At present,
the developer is encouraged to choose (as they have to call basicConfig anyway),
avoiding that bikeshedding altogether.

> The thing is, they don't *want* to configure them, but you force them
> to do some configuration if they don't want error messages to be
> silenced.

True, but it need be no more than a call to basicConfig(), so "not too
inconvenient" ;-)

> Sure. What I'm arguing is that the warnings module's default behaviour
> is much more useful than the logging module's default behaviour.

Sure, that's what we're discussing, all right.

>> That's why I was asked to add
>> warnings integration to logging - to redirect warning messages to logging.
> That's a separate topic :)

If you say so ;-)
>> (b) For this case, since there's no telepathy in this world, you need some
>> way for the programmer to communicate their intent about the logging level,
>> or format string, or log file that they want to use.
> Well, the programmer doesn't have to communicate their intent about
> what and how warnings get displayed by default, and I'm not sure the
> warnings module has a telepathy routine inside (although you never
> know, since IIRC Brett did some philosophy studies).

See my earlier comment about formatting and the potential for bikeshedding ;-)


Vinay Sajip

More information about the Python-Dev mailing list