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.
|