Changeset - a5a17000e45b
[Not reviewed]
celery
0 1 0
Marcin Kuzminski - 15 years ago 2010-09-21 15:36:46
marcin@python-works.com
timeproxy logging memory leak fix.
1 file changed with 12 insertions and 11 deletions:
0 comments (0 inline, 0 general)
pylons_app/lib/timerproxy.py
Show inline comments
 
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 @@ def format_sql(sql):
 
    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 @@ def format_sql(sql):
 

	
 

	
 
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)
0 comments (0 inline, 0 general)