summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-09-20 09:55:00 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-09-20 09:55:00 (GMT)
commitb4a0809ad79dbbd9c263b523499b8f0a0136aa7a (patch)
tree05530a4d7b91411c3d28dc05e36f1f28d1400066 /Lib/logging
parentf1d633c386646d83c03934f47ff064847ff2a3da (diff)
downloadcpython-b4a0809ad79dbbd9c263b523499b8f0a0136aa7a.zip
cpython-b4a0809ad79dbbd9c263b523499b8f0a0136aa7a.tar.gz
cpython-b4a0809ad79dbbd9c263b523499b8f0a0136aa7a.tar.bz2
logging: Add hasHandlers() method to Logger.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 6332f2f..134d923 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1240,6 +1240,28 @@ class Logger(Filterer):
finally:
hdlr.release()
+ def hasHandlers(self):
+ """
+ See if this logger has any handlers configured.
+
+ Loop through all handlers for this logger and its parents in the
+ logger hierarchy. Return True if a handler was found, else False.
+ Stop searching up the hierarchy whenever a logger with the "propagate"
+ attribute set to zero is found - that will be the last logger which
+ is checked for the existence of handlers.
+ """
+ c = self
+ rv = False
+ while c:
+ if c.handlers:
+ rv = True
+ break
+ if not c.propagate:
+ break
+ else:
+ c = c.parent
+ return rv
+
def callHandlers(self, record):
"""
Pass a record to all relevant handlers.