summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/logging.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/logging.py')
-rw-r--r--lib/sqlalchemy/logging.py62
1 files changed, 36 insertions, 26 deletions
diff --git a/lib/sqlalchemy/logging.py b/lib/sqlalchemy/logging.py
index 57e7bcfd7..4711b3155 100644
--- a/lib/sqlalchemy/logging.py
+++ b/lib/sqlalchemy/logging.py
@@ -4,17 +4,18 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""Provides a few functions used by instances to turn on/off their
-logging, including support for the usual "echo" parameter.
+"""Logging control and utilities.
-Control of logging for SA can be performed from the regular python
-logging module. The regular dotted module namespace is used, starting
-at 'sqlalchemy'. For class-level logging, the class name is appended,
-and for instance-level logging, the hex id of the instance is
-appended.
+Provides a few functions used by instances to turn on/off their logging,
+including support for the usual "echo" parameter.
-The "echo" keyword parameter which is available on some SA objects
-corresponds to an instance-level logger for that instance.
+Control of logging for SA can be performed from the regular python logging
+module. The regular dotted module namespace is used, starting at
+'sqlalchemy'. For class-level logging, the class name is appended, and for
+instance-level logging, the hex id of the instance is appended.
+
+The "echo" keyword parameter which is available on some SA objects corresponds
+to an instance-level logger for that instance.
E.g.::
@@ -23,21 +24,22 @@ E.g.::
is equivalent to::
import logging
- logging.getLogger('sqlalchemy.engine.Engine.%s' % hex(id(engine))).setLevel(logging.DEBUG)
+ logger = logging.getLogger('sqlalchemy.engine.Engine.%s' % hex(id(engine)))
+ logger.setLevel(logging.DEBUG)
"""
import sys, warnings
+import sqlalchemy.exceptions as sa_exc
# py2.5 absolute imports will fix....
logging = __import__('logging')
-# why is this in the "logging" module?
-class SADeprecationWarning(DeprecationWarning):
- pass
-
+# moved to sqlalchemy.exceptions. this alias will be removed in 0.5.
+SADeprecationWarning = sa_exc.SADeprecationWarning
+
rootlogger = logging.getLogger('sqlalchemy')
rootlogger.setLevel(logging.WARN)
-warnings.filterwarnings("once", category=SADeprecationWarning)
+warnings.filterwarnings("once", category=sa_exc.SADeprecationWarning)
default_enabled = False
def default_logging(name):
@@ -47,14 +49,20 @@ def default_logging(name):
if not default_enabled:
default_enabled = True
handler = logging.StreamHandler(sys.stdout)
- handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s'))
+ handler.setFormatter(logging.Formatter(
+ '%(asctime)s %(levelname)s %(name)s %(message)s'))
rootlogger.addHandler(handler)
def _get_instance_name(instance):
- # since getLogger() does not have any way of removing logger objects from memory,
- # instance logging displays the instance id as a modulus of 16 to prevent endless memory growth
- # also speeds performance as logger initialization is apparently slow
- return instance.__class__.__module__ + "." + instance.__class__.__name__ + ".0x.." + hex(id(instance))[-2:]
+ # since getLogger() does not have any way of removing logger objects from
+ # memory, instance logging displays the instance id as a modulus of 16 to
+ # prevent endless memory growth also speeds performance as logger
+ # initialization is apparently slow
+ return "%s.%s.0x..%s" % (instance.__class__.__module__,
+ instance.__class__.__name__,
+ hex(id(instance))[-2:])
+ return (instance.__class__.__module__ + "." + instance.__class__.__name__ +
+ ".0x.." + hex(id(instance))[-2:])
def class_logger(cls):
return logging.getLogger(cls.__module__ + "." + cls.__name__)
@@ -83,13 +91,15 @@ def instance_logger(instance, echoflag=None):
return l
class echo_property(object):
- __doc__ = """when ``True``, enable log output for this element.
+ __doc__ = """\
+ When ``True``, enable log output for this element.
+
- This has the effect of setting the Python logging level for the
- namespace of this element's class and object reference. A value
- of boolean ``True`` indicates that the loglevel ``logging.INFO`` will be
- set for the logger, whereas the string value ``debug`` will set the loglevel
- to ``logging.DEBUG``.
+ This has the effect of setting the Python logging level for the namespace
+ of this element's class and object reference. A value of boolean ``True``
+ indicates that the loglevel ``logging.INFO`` will be set for the logger,
+ whereas the string value ``debug`` will set the loglevel to
+ ``logging.DEBUG``.
"""
def __get__(self, instance, owner):