##// END OF EJS Templates
timeproxy logging memory leak fix.
marcink -
r492:a5a17000 celery
parent child Browse files
Show More
@@ -1,7 +1,6 b''
1 1 from sqlalchemy.interfaces import ConnectionProxy
2 2 import time
3 import logging
4 log = logging.getLogger('timerproxy')
3 from sqlalchemy import log
5 4 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
6 5
7 6 def color_sql(sql):
@@ -22,7 +21,6 b' def format_sql(sql):'
22 21 sql = sql.replace('\n', '')
23 22 sql = one_space_trim(sql)
24 23 sql = sql\
25 .replace(',',',\n\t')\
26 24 .replace('SELECT', '\n\tSELECT \n\t')\
27 25 .replace('UPDATE', '\n\tUPDATE \n\t')\
28 26 .replace('DELETE', '\n\tDELETE \n\t')\
@@ -39,19 +37,22 b' def format_sql(sql):'
39 37
40 38
41 39 class TimerProxy(ConnectionProxy):
40
41 def __init__(self):
42 super(TimerProxy, self).__init__()
43 self.logging_name = 'timerProxy'
44 self.log = log.instance_logger(self, True)
45
42 46 def cursor_execute(self, execute, cursor, statement, parameters, context, executemany):
47
43 48 now = time.time()
44 49 try:
45 log.info(">>>>> STARTING QUERY >>>>>")
50 self.log.info(">>>>> STARTING QUERY >>>>>")
46 51 return execute(cursor, statement, parameters, context)
47 52 finally:
48 53 total = time.time() - now
49 54 try:
50 log.info(format_sql("Query: %s" % statement % parameters))
55 self.log.info(format_sql("Query: %s" % statement % parameters))
51 56 except TypeError:
52 log.info(format_sql("Query: %s %s" % (statement, parameters)))
53 log.info("<<<<< TOTAL TIME: %f <<<<<" % total)
54
55
56
57
57 self.log.info(format_sql("Query: %s %s" % (statement, parameters)))
58 self.log.info("<<<<< TOTAL TIME: %f <<<<<" % total)
General Comments 0
You need to be logged in to leave comments. Login now