diff options
Diffstat (limited to 'lib/sqlalchemy/log.py')
-rw-r--r-- | lib/sqlalchemy/log.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/sqlalchemy/log.py b/lib/sqlalchemy/log.py index 3f861d60a..49c779fed 100644 --- a/lib/sqlalchemy/log.py +++ b/lib/sqlalchemy/log.py @@ -28,7 +28,7 @@ is equivalent to:: import logging import sys - +from sqlalchemy import util rootlogger = logging.getLogger('sqlalchemy') if rootlogger.level == logging.NOTSET: @@ -58,22 +58,28 @@ def class_logger(cls, enable=False): cls.logger = logger _logged_classes.add(cls) + +class Identified(object): + @util.memoized_property + def logging_name(self): + # limit the number of loggers by chopping off the hex(id). + # some novice users unfortunately create an unlimited number + # of Engines in their applications which would otherwise + # cause the app to run out of memory. + return "0x...%s" % hex(id(self))[-4:] + + def instance_logger(instance, echoflag=None): - """create a logger for an instance. + """create a logger for an instance that implements :class:`Identified`. Warning: this is an expensive call which also results in a permanent increase in memory overhead for each call. Use only for low-volume, long-time-spanning objects. """ - - # limit the number of loggers by chopping off the hex(id). - # many novice users unfortunately create an unlimited number - # of Engines in their applications which would otherwise - # cause the app to run out of memory. - name = "%s.%s.0x...%s" % (instance.__class__.__module__, - instance.__class__.__name__, - hex(id(instance))[-4:]) + + name = "%s.%s.%s" % (instance.__class__.__module__, + instance.__class__.__name__, instance.logging_name) if echoflag is not None: l = logging.getLogger(name) |