logging: Added threading interlock in basicConfig().
This commit is contained in:
parent
588bd847fb
commit
1ab32f6ebe
|
@ -1497,22 +1497,28 @@ def basicConfig(**kwargs):
|
|||
using sys.stdout or sys.stderr), whereas FileHandler closes its stream
|
||||
when the handler is closed.
|
||||
"""
|
||||
if len(root.handlers) == 0:
|
||||
filename = kwargs.get("filename")
|
||||
if filename:
|
||||
mode = kwargs.get("filemode", 'a')
|
||||
hdlr = FileHandler(filename, mode)
|
||||
else:
|
||||
stream = kwargs.get("stream")
|
||||
hdlr = StreamHandler(stream)
|
||||
fs = kwargs.get("format", BASIC_FORMAT)
|
||||
dfs = kwargs.get("datefmt", None)
|
||||
fmt = Formatter(fs, dfs)
|
||||
hdlr.setFormatter(fmt)
|
||||
root.addHandler(hdlr)
|
||||
level = kwargs.get("level")
|
||||
if level is not None:
|
||||
root.setLevel(level)
|
||||
# Add thread safety in case someone mistakenly calls
|
||||
# basicConfig() from multiple threads
|
||||
_acquireLock()
|
||||
try:
|
||||
if len(root.handlers) == 0:
|
||||
filename = kwargs.get("filename")
|
||||
if filename:
|
||||
mode = kwargs.get("filemode", 'a')
|
||||
hdlr = FileHandler(filename, mode)
|
||||
else:
|
||||
stream = kwargs.get("stream")
|
||||
hdlr = StreamHandler(stream)
|
||||
fs = kwargs.get("format", BASIC_FORMAT)
|
||||
dfs = kwargs.get("datefmt", None)
|
||||
fmt = Formatter(fs, dfs)
|
||||
hdlr.setFormatter(fmt)
|
||||
root.addHandler(hdlr)
|
||||
level = kwargs.get("level")
|
||||
if level is not None:
|
||||
root.setLevel(level)
|
||||
finally:
|
||||
_releaseLock()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Utility functions at module level.
|
||||
|
|
Loading…
Reference in New Issue