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: logging.getLevelName returns a number
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: neves, stevepole, vinay.sajip
Priority: normal Keywords:

Created on 2004-08-12 21:56 by neves, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg22056 - (view) Author: Paulo Eduardo Neves (neves) Date: 2004-08-12 21:56
logging.getLevelName function doc says that it returns
the "textual representation of logging level", but if
the argument is already the level name, the log level
integer is returned. It should return the argument.

The problem is that if I add my own levels, and call
LoggerInstance.log( levelName, message ), the formatter
will save the level number in the log, insted of the
desired level name. 
msg22057 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2004-08-20 12:36
Logged In: YES 
user_id=308438

This is not a bug, it's by design. Current CVS throws an
exception if raiseExceptions is set and you pass anything
other than an integer as the log level. The CVS
documentation has also been updated to clarify that the
level passed in is the integer rather than the level name.
msg22058 - (view) Author: Steve Pole (stevepole) Date: 2006-09-20 04:06
Logged In: YES 
user_id=455201

I understand this is not a bug, it's by design.

It still looks like a bug, though. Please consider the
following code:

import logging

defaultLoglevel = logging.DEBUG
newLoglevel     = 'WARNING'

logging.basicConfig (level = defaultLoglevel, format =
'%(message)s')
print logging.getLevelName (logging.getLogger
().getEffectiveLevel ())
print logging.getLogger ().getEffectiveLevel ()
logging.getLogger ().setLevel (newLoglevel.upper ())
print logging.getLevelName (logging.getLogger
().getEffectiveLevel ())
print logging.getLogger ().getEffectiveLevel ()

Output:
DEBUG
10
30
WARNING

So the result basically inverts. Is that really the way it
is supposed to work ?

Or am I misunderstanding something ?
msg22059 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-09-20 13:47
Logged In: YES 
user_id=308438

Yes, that's the way it's supposed to work - the map works
both ways, allowing the mapping of names to levels as well
as levels to names. This is because both types of mapping
are needed in the package, and it makes sense to reuse the 
dictionary rather than have two separate dictionaries.

In your example, you are calling setLevel with a string
argument [newLoglevel.upper ()], which is incorrect.

I will clarify the setLevel() documentation to point out
that the level passed to setLevel() is an integer.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40750
2004-08-12 21:56:31nevescreate