summaryrefslogtreecommitdiffstats
path: root/Lib/logging/__init__.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-03-22 15:29:01 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-03-22 15:29:01 (GMT)
commit804899b4ab873144ffc12c145fc4266489454c21 (patch)
treec89bb1594b095118133cce17144ce430f8c1c3e2 /Lib/logging/__init__.py
parent73c22e9df2ec56ae5ff756d4af39d819a43af178 (diff)
downloadcpython-804899b4ab873144ffc12c145fc4266489454c21.zip
cpython-804899b4ab873144ffc12c145fc4266489454c21.tar.gz
cpython-804899b4ab873144ffc12c145fc4266489454c21.tar.bz2
logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Diffstat (limited to 'Lib/logging/__init__.py')
-rw-r--r--Lib/logging/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 088c1fc..239ae61 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1316,6 +1316,25 @@ class Logger(Filterer):
return 0
return level >= self.getEffectiveLevel()
+ def getChild(self, suffix):
+ """
+ Get a logger which is a descendant to this one.
+
+ This is a convenience method, such that
+
+ logging.getLogger('abc').getChild('def.ghi')
+
+ is the same as
+
+ logging.getLogger('abc.def.ghi')
+
+ It's useful, for example, when the parent logger is named using
+ __name__ rather than a literal string.
+ """
+ if self.root is not self:
+ suffix = '.'.join((self.name, suffix))
+ return self.manager.getLogger(suffix)
+
class RootLogger(Logger):
"""
A root logger is not that different to any other logger, except that
@@ -1420,6 +1439,12 @@ class LoggerAdapter(object):
msg, kwargs = self.process(msg, kwargs)
self.logger.log(level, msg, *args, **kwargs)
+ def isEnabledFor(self, level):
+ """
+ See if the underlying logger is enabled for the specified level.
+ """
+ return self.logger.isEnabledFor(level)
+
root = RootLogger(WARNING)
Logger.root = root
Logger.manager = Manager(Logger.root)