diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-02-07 01:37:08 +0000 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-02-07 01:37:08 +0000 |
commit | 657514a69039ad60af1b3b98254dff863d800d95 (patch) | |
tree | af6171e5f24cc66c1dc36526cd1d2605a5393e8f /Lib/logging | |
parent | 12cad204a0e9f026c5a4f4d486e059d51af7cd92 (diff) | |
download | cpython-git-657514a69039ad60af1b3b98254dff863d800d95.tar.gz |
Issue #7868: logging: added loggerClass attribute to Manager.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index b5390cc8c1..5c727b0fe1 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -46,8 +46,8 @@ except ImportError: __author__ = "Vinay Sajip <vinay_sajip@red-dove.com>" __status__ = "production" -__version__ = "0.5.1.1" -__date__ = "25 November 2009" +__version__ = "0.5.1.2" +__date__ = "07 February 2010" #--------------------------------------------------------------------------- # Miscellaneous module data @@ -962,6 +962,7 @@ class Manager(object): self.disable = 0 self.emittedNoHandlerWarning = 0 self.loggerDict = {} + self.loggerClass = None def getLogger(self, name): """ @@ -981,13 +982,13 @@ class Manager(object): rv = self.loggerDict[name] if isinstance(rv, PlaceHolder): ph = rv - rv = _loggerClass(name) + rv = (self.loggerClass or _loggerClass)(name) rv.manager = self self.loggerDict[name] = rv self._fixupChildren(ph, rv) self._fixupParents(rv) else: - rv = _loggerClass(name) + rv = (self.loggerClass or _loggerClass)(name) rv.manager = self self.loggerDict[name] = rv self._fixupParents(rv) @@ -995,6 +996,16 @@ class Manager(object): _releaseLock() return rv + def setLoggerClass(self, klass): + """ + Set the class to be used when instantiating a logger with this Manager. + """ + if klass != Logger: + if not issubclass(klass, Logger): + raise TypeError("logger not derived from logging.Logger: " + + klass.__name__) + self.loggerClass = klass + def _fixupParents(self, alogger): """ Ensure that there are either loggers or placeholders all the way |