[Python-Dev] Redirecting warnings.showwarning to logging

Sidnei da Silva sidnei at enfoldsystems.com
Sat Nov 22 21:12:44 CET 2008


On Sat, Nov 22, 2008 at 9:12 AM, Vinay Sajip <vinay_sajip at yahoo.co.uk> wrote:
> Brett Cannon has suggested [1] that the logging package should provide an
> implementation of warnings.showwarning which redirects to logging. Here are my
> first thoughts about how this might work:
>
> A new function, showwarning( message, category, filename, lineno[, file]) will
> be added to the logging package. To redirect all warnings to the logging system,
> it will only be necessary to do the following:
>
> warnings.showwarning = logging.showwarning
<snip>
>
> Does this sound like a reasonable approach? Can someone please suggest any
> improvements, or let me know if I've missed anything?

I do have one suggestion for improvement: instead of requiring the
person to do this monkey patching, add a new 'log' action to the
warnings filter as described by PEP 230 [1] (see: 'The Warnings
Filter' section). This way, changing the behavior of how warnings are
displayed (or not) is kept consistent and documented.

[1] http://www.python.org/dev/peps/pep-0230/

-- 
Sidnei da Silva
Enfold Systems
http://enfoldsystems.com
Fax +1 832 201 8856
Office +1 713 942 2377 Ext 214
Skype zopedc


More information about the Python-Dev mailing list