aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/logging/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/logging/__init__.py')
-rw-r--r--Lib/logging/__init__.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index aa9b79d8cab..283a1055182 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1474,6 +1474,8 @@ class Logger(Filterer):
level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels.
There is no arbitrary limit to the depth of nesting.
"""
+ _tls = threading.local()
+
def __init__(self, name, level=NOTSET):
"""
Initialize the logger with a name and an optional level.
@@ -1670,14 +1672,19 @@ class Logger(Filterer):
This method is used for unpickled records received from a socket, as
well as those created locally. Logger-level filtering is applied.
"""
- if self.disabled:
- return
- maybe_record = self.filter(record)
- if not maybe_record:
+ if self._is_disabled():
return
- if isinstance(maybe_record, LogRecord):
- record = maybe_record
- self.callHandlers(record)
+
+ self._tls.in_progress = True
+ try:
+ maybe_record = self.filter(record)
+ if not maybe_record:
+ return
+ if isinstance(maybe_record, LogRecord):
+ record = maybe_record
+ self.callHandlers(record)
+ finally:
+ self._tls.in_progress = False
def addHandler(self, hdlr):
"""
@@ -1765,7 +1772,7 @@ class Logger(Filterer):
"""
Is this logger enabled for level 'level'?
"""
- if self.disabled:
+ if self._is_disabled():
return False
try:
@@ -1815,6 +1822,11 @@ class Logger(Filterer):
if isinstance(item, Logger) and item.parent is self and
_hierlevel(item) == 1 + _hierlevel(item.parent))
+ def _is_disabled(self):
+ # We need to use getattr as it will only be set the first time a log
+ # message is recorded on any given thread
+ return self.disabled or getattr(self._tls, 'in_progress', False)
+
def __repr__(self):
level = getLevelName(self.getEffectiveLevel())
return '<%s %s (%s)>' % (self.__class__.__name__, self.name, level)