mirror of https://github.com/python/cpython.git
Issue #6314: logging: Extra checks on the "level" argument in more places.
This commit is contained in:
parent
d50a5d5deb
commit
cbb24b35a0
|
@ -174,6 +174,17 @@ def addLevelName(level, levelName):
|
||||||
finally:
|
finally:
|
||||||
_releaseLock()
|
_releaseLock()
|
||||||
|
|
||||||
|
def _checkLevel(level):
|
||||||
|
if isinstance(level, int):
|
||||||
|
rv = level
|
||||||
|
elif str(level) == level:
|
||||||
|
if level not in _levelNames:
|
||||||
|
raise ValueError("Unknown level: %r" % level)
|
||||||
|
rv = _levelNames[level]
|
||||||
|
else:
|
||||||
|
raise TypeError("Level not an integer or a valid string: %r" % level)
|
||||||
|
return rv
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Thread-related stuff
|
# Thread-related stuff
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
@ -593,7 +604,7 @@ def __init__(self, level=NOTSET):
|
||||||
and the filter list to empty.
|
and the filter list to empty.
|
||||||
"""
|
"""
|
||||||
Filterer.__init__(self)
|
Filterer.__init__(self)
|
||||||
self.level = level
|
self.level = _checkLevel(level)
|
||||||
self.formatter = None
|
self.formatter = None
|
||||||
#get the module data lock, as we're updating a shared structure.
|
#get the module data lock, as we're updating a shared structure.
|
||||||
_acquireLock()
|
_acquireLock()
|
||||||
|
@ -631,7 +642,7 @@ def setLevel(self, level):
|
||||||
"""
|
"""
|
||||||
Set the logging level of this handler.
|
Set the logging level of this handler.
|
||||||
"""
|
"""
|
||||||
self.level = level
|
self.level = _checkLevel(level)
|
||||||
|
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
"""
|
"""
|
||||||
|
@ -1010,7 +1021,7 @@ def __init__(self, name, level=NOTSET):
|
||||||
"""
|
"""
|
||||||
Filterer.__init__(self)
|
Filterer.__init__(self)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.level = level
|
self.level = _checkLevel(level)
|
||||||
self.parent = None
|
self.parent = None
|
||||||
self.propagate = 1
|
self.propagate = 1
|
||||||
self.handlers = []
|
self.handlers = []
|
||||||
|
@ -1020,7 +1031,7 @@ def setLevel(self, level):
|
||||||
"""
|
"""
|
||||||
Set the logging level of this logger.
|
Set the logging level of this logger.
|
||||||
"""
|
"""
|
||||||
self.level = level
|
self.level = _checkLevel(level)
|
||||||
|
|
||||||
def debug(self, msg, *args, **kwargs):
|
def debug(self, msg, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -1397,10 +1408,6 @@ def basicConfig(**kwargs):
|
||||||
root.addHandler(hdlr)
|
root.addHandler(hdlr)
|
||||||
level = kwargs.get("level")
|
level = kwargs.get("level")
|
||||||
if level is not None:
|
if level is not None:
|
||||||
if str(level) == level: # If a string was passed, do more checks
|
|
||||||
if level not in _levelNames:
|
|
||||||
raise ValueError("Unknown level: %r" % level)
|
|
||||||
level = _levelNames[level]
|
|
||||||
root.setLevel(level)
|
root.setLevel(level)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
10
Misc/NEWS
10
Misc/NEWS
|
@ -350,12 +350,14 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #6314: logging: Extra checks on the "level" argument in more places.
|
||||||
|
|
||||||
- Issue #2622: Fixed an ImportError when importing email.messsage from a
|
- Issue #2622: Fixed an ImportError when importing email.messsage from a
|
||||||
standalone application built with py2exe or py2app.
|
standalone application built with py2exe or py2app.
|
||||||
|
|
||||||
- Issue #6455: Fixed test_build_ext under win32.
|
- Issue #6455: Fixed test_build_ext under win32.
|
||||||
|
|
||||||
- Issue #6377: Enabled the compiler option, and deprecate its usage as an
|
- Issue #6377: Enabled the compiler option, and deprecate its usage as an
|
||||||
attribute.
|
attribute.
|
||||||
|
|
||||||
- Issue #6413: Fixed the log level in distutils.dist for announce.
|
- Issue #6413: Fixed the log level in distutils.dist for announce.
|
||||||
|
@ -365,11 +367,11 @@ Library
|
||||||
|
|
||||||
- Issue #6403: Fixed package path usage in build_ext.
|
- Issue #6403: Fixed package path usage in build_ext.
|
||||||
|
|
||||||
- Issues #5155, 5313, 5331: multiprocessing.Process._bootstrap was
|
- Issues #5155, 5313, 5331: multiprocessing.Process._bootstrap was
|
||||||
unconditionally calling "os.close(sys.stdin.fileno())" resulting in file
|
unconditionally calling "os.close(sys.stdin.fileno())" resulting in file
|
||||||
descriptor errors
|
descriptor errors
|
||||||
|
|
||||||
- Issue #6365: Distutils build_ext inplace mode was copying the compiled
|
- Issue #6365: Distutils build_ext inplace mode was copying the compiled
|
||||||
extension in a subdirectory if the extension name had dots.
|
extension in a subdirectory if the extension name had dots.
|
||||||
|
|
||||||
- Issue #6344: Fixed a crash of mmap.read() when passed a negative argument.
|
- Issue #6344: Fixed a crash of mmap.read() when passed a negative argument.
|
||||||
|
|
Loading…
Reference in New Issue