[Python-Dev] PEP282 and the warnings framework

Guido van Rossum guido@python.org
Wed, 15 May 2002 10:19:13 -0400


> I've reread PEP 282 (the logging PEP) and much of what I read
> reminded me of the warning framework.
> 
> Both systems are responsible for reporting (or ignoring) messages.
> Both associate messages with locations in the source where the
> messages originated and both have a way to configure what to report
> and what to ignore.
> 
> So I guess it would make sense to somehow merge the two APIs.

What follows doesn't really seem to *merge* the two APIs, it just
picks a clever trick used by the warnings framework and applies it to
the logging API.  I won't comment on whether this fits the logging
API; if the folks who wrote the PEP and the implementation agree that
it is a good idea, there will be time to integrate this into Python
2.3.

But I want to warn against any attempts to go further and actually
*unify* the two APIs (in the sense of designing a single API used for
both purposes).

IMO the goals of logging and the warnings framework are quite
different: the warnings framework is for the benefit of the
*programmer*, while the logging framework is for the benefit of the
*end user*.  While both act at run-time, warnings are typically about
code that is doing something that may not be right (such as the import
of a deprecated module), while logging is about situations in the
"real" world that may need to be brought to the attention of the user
(for example a disk filling up).

While similar approaches to filtering may apply, in general the
destination of warnings and logging messages should not be mixed up.

If there were any warnings left in a program by the time it was
deployed in the field, as a user I'd want to have a hearty word with
the programmer.  The program probably should have been tested with
-Werror, turning all warnings into errors, or (if it's impossible to
silence all warnings for some reason) with -Wignore -- but the
programmer better have a darn good excuse in the latter case.

--Guido van Rossum (home page: http://www.python.org/~guido/)