]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
some logging tweaks....its a little squirrely
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Oct 2006 18:01:11 +0000 (18:01 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 12 Oct 2006 18:01:11 +0000 (18:01 +0000)
lib/sqlalchemy/logging.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/unitofwork.py

index fe5c5c0e5b203136be77cd45192430d9a3853597..3a5a19fa81c7d7c5e4d9c5f30afd243f2a1dc08b 100644 (file)
@@ -30,8 +30,10 @@ import sys
 logging = __import__('logging')
 
 default_enabled = False
-def default_logging():
+def default_logging(name):
     global default_enabled
+    if logging.getLogger(name).getEffectiveLevel() < logging.WARN:
+        default_enabled=True
     if not default_enabled:
         default_enabled = True
         rootlogger = logging.getLogger('sqlalchemy')
@@ -58,13 +60,13 @@ def is_info_enabled(logger):
     return logger.isEnabledFor(logging.INFO)
         
 class echo_property(object):
-    level_map={logging.DEBUG : "debug", logging.NOTSET : False}
+    level_map={logging.DEBUG : "debug", logging.INFO:True}
     def __get__(self, instance, owner):
         level = logging.getLogger(_get_instance_name(instance)).getEffectiveLevel()
-        return echo_property.level_map.get(level, True)
+        return echo_property.level_map.get(level, False)
     def __set__(self, instance, value):
         if value:
-            default_logging()
+            default_logging(_get_instance_name(instance))
             logging.getLogger(_get_instance_name(instance)).setLevel(value == 'debug' and logging.DEBUG or logging.INFO)
         else:
             logging.getLogger(_get_instance_name(instance)).setLevel(logging.NOTSET)
index b12ee4e84cfc7dc07c3edf91f9fbee2fa3f4ddb6..fef887f7bfd137b275390e6bf0565b51858ef660 100644 (file)
@@ -134,7 +134,9 @@ class Session(object):
         objects in this Session."""
         for instance in self:
             self._unattach(instance)
+        echo = self.uow.echo
         self.uow = unitofwork.UnitOfWork()
+        self.uow.echo = echo
             
     def mapper(self, class_, entity_name=None):
         """given an Class, returns the primary Mapper responsible for persisting it"""
@@ -230,7 +232,7 @@ class Session(object):
         
         'objects' is a list or tuple of objects specifically to be flushed; if None, all
         new and modified objects are flushed."""
-        self.uow.flush(self, objects, echo=self.echo_uow)
+        self.uow.flush(self, objects)
 
     def get(self, class_, ident, **kwargs):
         """return an instance of the object based on the given identifier, or None if not found.  
index 2beb6a78eb68b7c2180a4e22a0b2167eba1300d5..5c2e21c5fa2468c18bcea3fe88fb885f6943a73f 100644 (file)
@@ -138,7 +138,7 @@ class UnitOfWork(object):
     def locate_dirty(self):
         return util.Set([x for x in self.identity_map.values() if x not in self.deleted and attribute_manager.is_modified(x)])
         
-    def flush(self, session, objects=None, echo=False):
+    def flush(self, session, objects=None):
         # this context will track all the objects we want to save/update/delete,
         # and organize a hierarchical dependency structure.  it also handles
         # communication with the mappers and relationships to fire off SQL
@@ -185,7 +185,7 @@ class UnitOfWork(object):
         trans = session.create_transaction(autoflush=False)
         flush_context.transaction = trans
         try:
-            flush_context.execute(echo=echo)
+            flush_context.execute()
         except:
             trans.rollback()
             raise
@@ -206,6 +206,9 @@ class UOWTransaction(object):
         self.__modified = False
         self.__is_executing = False
         self.logger = logging.instance_logger(self)
+        self.echo = uow.echo
+        
+    echo = logging.echo_property()
     
     def register_object(self, obj, isdelete = False, listonly = False, postupdate=False, post_update_cols=None, **kwargs):
         """adds an object to this UOWTransaction to be updated in the database.
@@ -306,7 +309,7 @@ class UOWTransaction(object):
         task.dependencies.add(up)
         self._mark_modified()
 
-    def execute(self, echo=False):
+    def execute(self):
         # insure that we have a UOWTask for every mapper that will be involved 
         # in the topological sort
         [self.get_task_by_mapper(m) for m in self._get_noninheriting_mappers()]
@@ -333,7 +336,7 @@ class UOWTransaction(object):
         
         head = self._sort_dependencies()
         self.__modified = False
-        if echo:
+        if self.echo:
             if head is None:
                 self.logger.info("Task dump: None")
             else:
@@ -342,8 +345,7 @@ class UOWTransaction(object):
             head.execute(self)
         #if self.__modified and head is not None:
         #    raise "Assertion failed ! new pre-execute dependency step should eliminate post-execute changes (except post_update stuff)."
-        if echo:
-            self.logger.info("Execute Complete")
+        self.logger.info("Execute Complete")
             
     def post_exec(self):
         """after an execute/flush is completed, all of the objects and lists that have