[ python-Bugs-992397 ] variable reuse in the logging module

SourceForge.net noreply at sourceforge.net
Mon Aug 2 12:42:02 CEST 2004


Bugs item #992397, was opened at 2004-07-16 15:18
Message generated for change (Settings changed) made by vsajip
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=992397&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 1
Submitted By: Gintautas Miliauskas (gintautasm)
>Assigned to: Vinay Sajip (vsajip)
Summary: variable reuse in the logging module

Initial Comment:
I accidentally tried to pass logging levels as strings
to Logger.log() instead of numbers. The result was that
%(levelname)s produced the number of the level
specified and %(levelno)s produced the name... I
assumed that passing strings was valid, because if you
passed an unregistered level name, the %(levelname)s
would just say 'Level XYZ' instead of 'XYZ'.

The culprit is this dict in logging/__init__.py:

_levelNames = {
    CRITICAL : 'CRITICAL',
    ERROR : 'ERROR',
    WARNING : 'WARNING',
    INFO : 'INFO',
    DEBUG : 'DEBUG',
    NOTSET : 'NOTSET',
    'CRITICAL' : CRITICAL,
    'ERROR' : ERROR,
    'WARN' : WARNING,
    'WARNING' : WARNING,
    'INFO' : INFO,
    'DEBUG' : DEBUG,
    'NOTSET' : NOTSET,
}

I think it would be a good idea to split this dict into
two, so that such confusion doesn't result. Also, it
should be explicitly stated (in the docs and maybe in
code too) if a name of the level as a string argument
to Logger.log() is valid or not.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=992397&group_id=5470


More information about the Python-bugs-list mailing list