[Python-Dev] Backwards Incompatibility in logging module in 3.4?

Victor Stinner victor.stinner at gmail.com
Fri Jun 13 01:45:13 CEST 2014


Hi,

2014-06-13 0:38 GMT+02:00 Don Spaulding <donspauldingii at gmail.com>:
> Is this a bug or an intentional break?  If it's the latter, shouldn't this
> at least be mentioned in the "What's new in Python 3.4" document?

IMO the change is intentional. The previous behaviour was not really expected.

Python 3.3 documentation is explicit: the result is a string and the
input paramter is an integer. logging.getLevelName("DEBUG") was more
an implementation

https://docs.python.org/3.3/library/logging.html#logging.getLevelName
"Returns the textual representation of logging level lvl. If the level
is one of the predefined levels CRITICAL, ERROR, WARNING, INFO or
DEBUG then you get the corresponding string. If you have associated
levels with names using addLevelName() then the name you have
associated with lvl is returned. If a numeric value corresponding to
one of the defined levels is passed in, the corresponding string
representation is returned. Otherwise, the string ‘Level %s’ % lvl is
returned."

If your code uses something like
logger.setLevel(logging.getLevelName("DEBUG")), use directly
logger.setLevel("DEBUG").

This issue was fixed in OpenStack with this change:
https://review.openstack.org/#/c/94028/6/openstack/common/log.py,cm
https://review.openstack.org/#/c/94028/6

Victor


More information about the Python-Dev mailing list