From 7cf31b4869e49efa4013ddbcdf837ab94a739cf8 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 3 Sep 2010 09:41:32 +0200 Subject: [IMP] display database name in the logger bzr revid: chs@openerp.com-20100903074132-nrhd3p2i53hmtt9j --- bin/sql_db.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index 5ed7b14c0df..76a9e6f5f7c 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -21,6 +21,7 @@ __all__ = ['db_connect', 'close_db'] +from threading import current_thread import logging from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_SERIALIZABLE from psycopg2.psycopg1 import cursor as psycopg1cursor @@ -362,11 +363,15 @@ def dsn_are_equals(first, second): _Pool = ConnectionPool(int(tools.config['db_maxconn'])) def db_connect(db_name): + current_thread().dbname = db_name return Connection(_Pool, db_name) def close_db(db_name): _Pool.close_all(dsn(db_name)) tools.cache.clean_caches_for_db(db_name) + ct = current_thread() + if hasattr(ct, 'dbname'): + delattr(ct, 'dbname') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: -- cgit v1.2.3 From ef4151fcb970178d51ac9b9e6a9e02be9f5d48c2 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 3 Sep 2010 10:58:04 +0200 Subject: [IMP] sql_db: promote some debug_sql to info or warning bzr revid: chs@openerp.com-20100903085804-p0yij5nly1d076c7 --- bin/sql_db.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index 76a9e6f5f7c..28676d772db 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## @@ -126,7 +126,7 @@ class Cursor(object): self.__logger.error("Programming error: %s, in query %s", pe, query) raise except Exception: - self.__logger.exception("bad query: %s", self._obj.query) + self.__logger.exception("bad query: %s", self._obj.query or query) raise if self.sql_log: @@ -268,7 +268,7 @@ class ConnectionPool(object): delattr(cnx, 'leaked') self._connections.pop(i) self._connections.append((cnx, False)) - self._debug('Free leaked connection to %r', cnx.dsn) + self.__logger.warn('%r: Free leaked connection to %r', self, cnx.dsn) for i, (cnx, used) in enumerate(self._connections): if not used and dsn_are_equals(cnx.dsn, dsn): @@ -311,7 +311,7 @@ class ConnectionPool(object): @locked def close_all(self, dsn): - self._debug('Close all connections to %r', dsn) + self.__logger.info('%r: Close all connections to %r', self, dsn) for i, (cnx, used) in tools.reverse_enumerate(self._connections): if dsn_are_equals(cnx.dsn, dsn): cnx.close() -- cgit v1.2.3 From 0cc75127a8bb4cc342a3a55d7aae731dd315421f Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 3 Sep 2010 14:24:26 +0200 Subject: [IMP] sql_db.cursor: optional 'log_exceptions' flag to turn off logging exceptions inside the cr.execute() method This is useful when the caller wants to do the logging. bzr revid: odo@openerp.com-20100903122426-fox86td4uqr3l0jx --- bin/sql_db.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index 28676d772db..438d513b0e4 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -108,7 +108,7 @@ class Cursor(object): self._close(True) @check - def execute(self, query, params=None): + def execute(self, query, params=None, log_exceptions=True): if '%d' in query or '%f' in query: self.__logger.warn(query) self.__logger.warn("SQL queries cannot contain %d or %f anymore. " @@ -123,10 +123,12 @@ class Cursor(object): params = params or None res = self._obj.execute(query, params) except psycopg2.ProgrammingError, pe: - self.__logger.error("Programming error: %s, in query %s", pe, query) + if log_exceptions or self.sql_log: + self.__logger.error("Programming error: %s, in query %s", pe, query) raise except Exception: - self.__logger.exception("bad query: %s", self._obj.query or query) + if log_exceptions or self.sql_log: + self.__logger.exception("bad query: %s", self._obj.query or query) raise if self.sql_log: -- cgit v1.2.3 From 6b2e5f98962958b8480f629d0b336a3d88bf0066 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Mon, 6 Sep 2010 16:06:45 +0200 Subject: [FIX] Use the currentThread function instead of current_thread bzr revid: stephane@openerp.com-20100906140645-zxt6los8sl54qzj0 --- bin/sql_db.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index 438d513b0e4..193a709dd8d 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -21,7 +21,7 @@ __all__ = ['db_connect', 'close_db'] -from threading import current_thread +from threading import currentThread import logging from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_SERIALIZABLE from psycopg2.psycopg1 import cursor as psycopg1cursor @@ -365,13 +365,13 @@ def dsn_are_equals(first, second): _Pool = ConnectionPool(int(tools.config['db_maxconn'])) def db_connect(db_name): - current_thread().dbname = db_name + currentThread().dbname = db_name return Connection(_Pool, db_name) def close_db(db_name): _Pool.close_all(dsn(db_name)) tools.cache.clean_caches_for_db(db_name) - ct = current_thread() + ct = currentThread() if hasattr(ct, 'dbname'): delattr(ct, 'dbname') -- cgit v1.2.3 From 9c62cde38f7b99b004907ff3f249294fd20dcc4b Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 18 Sep 2010 11:30:52 +0200 Subject: [IMP] improve debug for --log-level=debug_sql bzr revid: fp@tinyerp.com-20100918093052-nxapeqahzt4cpr2m --- bin/sql_db.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bin/sql_db.py') diff --git a/bin/sql_db.py b/bin/sql_db.py index 193a709dd8d..6c2c17beeb3 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -113,8 +113,6 @@ class Cursor(object): self.__logger.warn(query) self.__logger.warn("SQL queries cannot contain %d or %f anymore. " "Use only %s") - if params: - query = query.replace('%d', '%s').replace('%f', '%s') if self.sql_log: now = mdt.now() @@ -167,6 +165,7 @@ class Cursor(object): sqllogitems = sqllogs[type].items() sqllogitems.sort(key=lambda k: k[1][1]) self.__logger.log(logging.DEBUG_SQL, "SQL LOG %s:", type) + sqllogitems.sort(lambda x,y: cmp(x[1][0], y[1][0])) for r in sqllogitems: delay = timedelta(microseconds=r[1][1]) self.__logger.log(logging.DEBUG_SQL, "table: %s: %s/%s", -- cgit v1.2.3