# HG changeset patch # User Marcin Kuzminski # Date 1285076206 -7200 # Node ID a5a17000e45bf26fc811fc8fb985d438b74c97fc # Parent fefffd6fd5f4a1aceddfa90262ef6ce4541016c2 timeproxy logging memory leak fix. diff -r fefffd6fd5f4 -r a5a17000e45b pylons_app/lib/timerproxy.py --- a/pylons_app/lib/timerproxy.py Tue Sep 21 01:08:01 2010 +0200 +++ b/pylons_app/lib/timerproxy.py Tue Sep 21 15:36:46 2010 +0200 @@ -1,7 +1,6 @@ from sqlalchemy.interfaces import ConnectionProxy import time -import logging -log = logging.getLogger('timerproxy') +from sqlalchemy import log BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38) def color_sql(sql): @@ -22,7 +21,6 @@ sql = sql.replace('\n', '') sql = one_space_trim(sql) sql = sql\ - .replace(',',',\n\t')\ .replace('SELECT', '\n\tSELECT \n\t')\ .replace('UPDATE', '\n\tUPDATE \n\t')\ .replace('DELETE', '\n\tDELETE \n\t')\ @@ -39,19 +37,22 @@ class TimerProxy(ConnectionProxy): + + def __init__(self): + super(TimerProxy, self).__init__() + self.logging_name = 'timerProxy' + self.log = log.instance_logger(self, True) + def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): + now = time.time() try: - log.info(">>>>> STARTING QUERY >>>>>") + self.log.info(">>>>> STARTING QUERY >>>>>") return execute(cursor, statement, parameters, context) finally: total = time.time() - now try: - log.info(format_sql("Query: %s" % statement % parameters)) + self.log.info(format_sql("Query: %s" % statement % parameters)) except TypeError: - log.info(format_sql("Query: %s %s" % (statement, parameters))) - log.info("<<<<< TOTAL TIME: %f <<<<<" % total) - - - - + self.log.info(format_sql("Query: %s %s" % (statement, parameters))) + self.log.info("<<<<< TOTAL TIME: %f <<<<<" % total)