This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: variable reuse in the logging module
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: gintautasm, vinay.sajip
Priority: low Keywords:

Created on 2004-07-16 15:18 by gintautasm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg21668 - (view) Author: Gintautas Miliauskas (gintautasm) Date: 2004-07-16 15:18
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.
msg21669 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2004-08-04 08:38
Logged In: YES 
user_id=308438

Current CVS Logger.log() throws an exception ("level must be 
an integer") if you don't pass an integer level, and if 
raiseExceptions is set.

The _levelNames approach is by design. It avoids having two 
dictionaries and two function calls.

Documentation/docstring for Logger.log() updated to indicate 
that "lvl" should be an integer.
History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40585
2004-07-16 15:18:46gintautasmcreate