diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-05-18 16:40:02 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-05-18 16:40:02 +0000 |
commit | 82f80559b9815da8a1695c9f266488da35eb2a97 (patch) | |
tree | 19182624ea8c4c6e66ff71bcf67c3b0944e1147c /lib/sqlalchemy/log.py | |
parent | 01b952c336d7e3e16af685ac113d04a66ef99940 (diff) | |
download | sqlalchemy-82f80559b9815da8a1695c9f266488da35eb2a97.tar.gz |
put a cleanup handler on the "echo" property to try preventing log garbage in the buildbot
Diffstat (limited to 'lib/sqlalchemy/log.py')
-rw-r--r-- | lib/sqlalchemy/log.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/sqlalchemy/log.py b/lib/sqlalchemy/log.py index 65100d469..06aa47eba 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) |