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

Antoine Pitrou solipsis at pitrou.net
Tue Dec 7 22:19:34 CET 2010


On Tue, 7 Dec 2010 22:04:36 +0100
Łukasz Langa <lukasz at langa.pl> wrote:
> Wiadomość napisana przez Antoine Pitrou w dniu 2010-12-07, o godz. 21:50:
> 
> > If any library defining a logger must also add a NullHandler just in
> > case, ISTM that complicates a lot the use of logging (and could explain
> > its impopularity). Both for library writers and application writers,
> > apparently (since the former will have to add the NullHandler, and the
> > latter will have to override it so that error messages get printed out
> > rather than lost).
> 
> ISTM that the stdlib is a special case here. If you're writing an application then the "No handlers could be found" message is actually useful because there's hardly any reason no to include one.

Why do you say that? Not having to add a handler is certainly useful
when you are doing some quick prototyping or simply writing a script
(situations in which you still want to get error messages displayed
properly by the libraries).

> One way or the other, we should really default to the convenience of application developers. This is currently the case.

Why wouldn't there be a default convenience of printing out errors?
It's already the case for the root handler, so why would other handler
be treated differently?

>>> import logging
>>> logging.debug("foo")
>>> logging.error("bar")
ERROR:root:bar

Thanks

Antoine.


More information about the Python-Dev mailing list