From: Mike Bayer Date: Sun, 18 May 2008 16:40:02 +0000 (+0000) Subject: put a cleanup handler on the "echo" property to try preventing log garbage in the... X-Git-Tag: rel_0_5beta1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82f80559b9815da8a1695c9f266488da35eb2a97;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git put a cleanup handler on the "echo" property to try preventing log garbage in the buildbot --- diff --git a/lib/sqlalchemy/log.py b/lib/sqlalchemy/log.py index 65100d4695..06aa47eba6 100644 --- a/lib/sqlalchemy/log.py +++ b/lib/sqlalchemy/log.py @@ -30,7 +30,7 @@ is equivalent to:: import logging import sys - +import weakref rootlogger = logging.getLogger('sqlalchemy') if rootlogger.level == logging.NOTSET: @@ -70,15 +70,23 @@ def is_info_enabled(logger): def instance_logger(instance, echoflag=None): if echoflag is not None: - l = logging.getLogger(_get_instance_name(instance)) + name = _get_instance_name(instance) + l = logging.getLogger(name) if echoflag == 'debug': - default_logging(_get_instance_name(instance)) + default_logging(name) l.setLevel(logging.DEBUG) elif echoflag is True: - default_logging(_get_instance_name(instance)) + default_logging(name) l.setLevel(logging.INFO) elif echoflag is False: l.setLevel(logging.NOTSET) + + def cleanup(ref): + # the id() of an instance may be reused again after the + # previous instance has been gc'ed. set a cleanup handler + # to remove logging config + logging.getLogger(name).setLevel(logging.NOTSET) + instance._logging_cleanup = weakref.ref(instance, cleanup) else: l = logging.getLogger(_get_instance_name(instance)) instance._should_log_debug = l.isEnabledFor(logging.DEBUG)