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