Index: Lib/logging/__init__.py =================================================================== --- Lib/logging/__init__.py (revision 53516) +++ Lib/logging/__init__.py (working copy) @@ -856,7 +856,8 @@ self.root = rootnode self.disable = 0 self.emittedNoHandlerWarning = 0 - self.loggerDict = {} + from weakref import WeakValueDictionary + self.loggerDict = WeakValueDictionary() def getLogger(self, name): """ Index: Lib/test/test_logging.py =================================================================== --- Lib/test/test_logging.py (revision 53451) +++ Lib/test/test_logging.py (working copy) @@ -568,6 +568,24 @@ logging._releaseLock() +def test6(): + class CounterLogger(logging.Logger): + counter = 0 + def __init__(self, *args, **kwargs): + logging.Logger.__init__(self, *args, **kwargs) + CounterLogger.counter += 1 + def __del__(self): + CounterLogger.counter -= 1 + logging.setLoggerClass(CounterLogger) + l = logging.getLogger("testleak") + l.info("OK got logger") + try: + assert CounterLogger.counter == 1 + del l + assert CounterLogger.counter == 0 + finally: + logging.setLoggerClass(logging.Logger) + #---------------------------------------------------------------------------- # Test Harness #---------------------------------------------------------------------------- @@ -635,7 +653,7 @@ banner("log_test0", "end") - for t in range(1,6): + for t in range(1,7): banner("log_test%d" % t, "begin") globals()['test%d' % t]() banner("log_test%d" % t, "end")