summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/log.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-13 13:53:31 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-13 13:53:31 -0500
commit5f1fbf575915470391c5a816d99a742e64b6be25 (patch)
treee47cc04988a835ef03f1b3bb02e5a5c4d0495e24 /lib/sqlalchemy/log.py
parent3290ac23df9eed8a61324eb68f062a7de29e549d (diff)
downloadsqlalchemy-5f1fbf575915470391c5a816d99a742e64b6be25.tar.gz
- Added "logging_name" argument to create_engine(), Pool() constructor
as well as "pool_logging_name" argument to create_engine() which filters down to that of Pool. Issues the given string name within the "name" field of logging messages instead of the default hex identifier string. [ticket:1555]
Diffstat (limited to 'lib/sqlalchemy/log.py')
-rw-r--r--lib/sqlalchemy/log.py26
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)