Add logging mechanism for notices from postgres server. Rename SQL log to "pgmanager_sql".
authorRadek Brich <radek.brich@devl.cz>
Fri, 13 Jan 2012 15:49:24 +0100
changeset 26 7f219da7ab71
parent 25 20a72a9a2d09
child 27 5fb4883604d6
Add logging mechanism for notices from postgres server. Rename SQL log to "pgmanager_sql".
pgtoolkit/pgmanager.py
--- a/pgtoolkit/pgmanager.py	Thu Dec 15 18:26:04 2011 +0100
+++ b/pgtoolkit/pgmanager.py	Fri Jan 13 15:49:24 2012 +0100
@@ -82,7 +82,8 @@
 from psycopg2 import DatabaseError, IntegrityError, OperationalError
 
 
-log = logging.getLogger("pgmanager")
+log_sql = logging.getLogger("pgmanager_sql")
+log_notices = logging.getLogger("pgmanager_notices")
 
 
 class PgManagerError(Exception):
@@ -115,14 +116,14 @@
             return super(Cursor, self).execute(query, args)
         finally:
             if self.query:
-                log.debug(self.query.decode('utf8'))
+                log_sql.info(self.query.decode('utf8'))
 
     def callproc(self, procname, args=None):
         try:
             return super(Cursor, self).callproc(procname, args)
         finally:
             if self.query:
-                log.debug(self.query.decode('utf8'))
+                log_sql.info(self.query.decode('utf8'))
 
     def row_dict(self, row, lstrip=None):
         adjustname = lambda a: a
@@ -306,8 +307,14 @@
             yield curs
         finally:
             curs.close()
+            self.log_notices(conn)
             self.put_conn(conn, name)
 
+    def log_notices(self, conn):
+        for notice in conn.notices:
+            log_notices.info(notice.rstrip())
+        conn.notices[:] = []
+
     def wait_for_notify(self, name='default', timeout=5):
         '''Wait for asynchronous notifies, return the last one.