##// END OF EJS Templates
timperproxy will just measure the time of queries, and formatting will be handled by the new sql_formatter of queries from sqlalchemy itself. Updated ini files for new way logging
marcink -
r1186:b9ea10d3 beta
parent child Browse files
Show More
@@ -143,21 +143,21 b' logview.pylons.util = #eee'
143 #########################################################
143 #########################################################
144 #sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
144 #sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
145 sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
145 sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
146 #sqlalchemy.db1.echo = False
146 sqlalchemy.db1.echo = True
147 #sqlalchemy.db1.pool_recycle = 3600
147 sqlalchemy.db1.pool_recycle = 3600
148 sqlalchemy.convert_unicode = true
148 sqlalchemy.convert_unicode = true
149
149
150 ################################
150 ################################
151 ### LOGGING CONFIGURATION ####
151 ### LOGGING CONFIGURATION ####
152 ################################
152 ################################
153 [loggers]
153 [loggers]
154 keys = root, routes, rhodecode, sqlalchemy,beaker,templates
154 keys = root, routes, rhodecode, sqlalchemy, beaker, templates
155
155
156 [handlers]
156 [handlers]
157 keys = console
157 keys = console, console_sql
158
158
159 [formatters]
159 [formatters]
160 keys = generic,color_formatter
160 keys = generic, color_formatter, color_formatter_sql
161
161
162 #############
162 #############
163 ## LOGGERS ##
163 ## LOGGERS ##
@@ -168,32 +168,32 b' handlers = console'
168
168
169 [logger_routes]
169 [logger_routes]
170 level = DEBUG
170 level = DEBUG
171 handlers = console
171 handlers =
172 qualname = routes.middleware
172 qualname = routes.middleware
173 # "level = DEBUG" logs the route matched and routing variables.
173 # "level = DEBUG" logs the route matched and routing variables.
174 propagate = 0
174 propagate = 1
175
175
176 [logger_beaker]
176 [logger_beaker]
177 level = ERROR
177 level = DEBUG
178 handlers = console
178 handlers =
179 qualname = beaker.container
179 qualname = beaker.container
180 propagate = 0
180 propagate = 1
181
181
182 [logger_templates]
182 [logger_templates]
183 level = INFO
183 level = INFO
184 handlers = console
184 handlers =
185 qualname = pylons.templating
185 qualname = pylons.templating
186 propagate = 0
186 propagate = 1
187
187
188 [logger_rhodecode]
188 [logger_rhodecode]
189 level = DEBUG
189 level = DEBUG
190 handlers = console
190 handlers =
191 qualname = rhodecode
191 qualname = rhodecode
192 propagate = 0
192 propagate = 1
193
193
194 [logger_sqlalchemy]
194 [logger_sqlalchemy]
195 level = ERROR
195 level = INFO
196 handlers = console
196 handlers = console_sql
197 qualname = sqlalchemy.engine
197 qualname = sqlalchemy.engine
198 propagate = 0
198 propagate = 0
199
199
@@ -207,6 +207,12 b' args = (sys.stderr,)'
207 level = NOTSET
207 level = NOTSET
208 formatter = color_formatter
208 formatter = color_formatter
209
209
210 [handler_console_sql]
211 class = StreamHandler
212 args = (sys.stderr,)
213 level = NOTSET
214 formatter = color_formatter_sql
215
210 ################
216 ################
211 ## FORMATTERS ##
217 ## FORMATTERS ##
212 ################
218 ################
@@ -218,4 +224,9 b' datefmt = %Y-%m-%d %H:%M:%S'
218 [formatter_color_formatter]
224 [formatter_color_formatter]
219 class=rhodecode.lib.colored_formatter.ColorFormatter
225 class=rhodecode.lib.colored_formatter.ColorFormatter
220 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
226 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
227 datefmt = %Y-%m-%d %H:%M:%S
228
229 [formatter_color_formatter_sql]
230 class=rhodecode.lib.colored_formatter.ColorFormatterSql
231 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
221 datefmt = %Y-%m-%d %H:%M:%S No newline at end of file
232 datefmt = %Y-%m-%d %H:%M:%S
@@ -29,7 +29,7 b' debug = true'
29 threadpool_workers = 5
29 threadpool_workers = 5
30
30
31 ##max request before thread respawn
31 ##max request before thread respawn
32 threadpool_max_requests = 6
32 threadpool_max_requests = 10
33
33
34 ##option to use threads of process
34 ##option to use threads of process
35 use_threadpool = true
35 use_threadpool = true
@@ -41,13 +41,14 b' port = 8001'
41 [app:main]
41 [app:main]
42 use = egg:rhodecode
42 use = egg:rhodecode
43 full_stack = true
43 full_stack = true
44 static_files = false
44 static_files = true
45 lang=en
45 lang=en
46 cache_dir = %(here)s/data
46 cache_dir = %(here)s/data
47 index_dir = %(here)s/data/index
47 index_dir = %(here)s/data/index
48 app_instance_uuid = prod1234
48 cut_off_limit = 256000
49 cut_off_limit = 256000
49 force_https = false
50 force_https = false
50 commit_parse_limit = 25
51 commit_parse_limit = 50
51 use_gravatar = true
52 use_gravatar = true
52
53
53 ####################################
54 ####################################
@@ -142,57 +143,57 b' logview.pylons.util = #eee'
142 #########################################################
143 #########################################################
143 #sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
144 #sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
144 sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
145 sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
145 #sqlalchemy.db1.echo = False
146 sqlalchemy.db1.echo = True
146 #sqlalchemy.db1.pool_recycle = 3600
147 sqlalchemy.db1.pool_recycle = 3600
147 sqlalchemy.convert_unicode = true
148 sqlalchemy.convert_unicode = true
148
149
149 ################################
150 ################################
150 ### LOGGING CONFIGURATION ####
151 ### LOGGING CONFIGURATION ####
151 ################################
152 ################################
152 [loggers]
153 [loggers]
153 keys = root, routes, rhodecode, sqlalchemy,beaker,templates
154 keys = root, routes, rhodecode, sqlalchemy, beaker, templates
154
155
155 [handlers]
156 [handlers]
156 keys = console
157 keys = console, console_sql
157
158
158 [formatters]
159 [formatters]
159 keys = generic,color_formatter
160 keys = generic, color_formatter, color_formatter_sql
160
161
161 #############
162 #############
162 ## LOGGERS ##
163 ## LOGGERS ##
163 #############
164 #############
164 [logger_root]
165 [logger_root]
165 level = INFO
166 level = NOTSET
166 handlers = console
167 handlers = console
167
168
168 [logger_routes]
169 [logger_routes]
169 level = INFO
170 level = DEBUG
170 handlers = console
171 handlers =
171 qualname = routes.middleware
172 qualname = routes.middleware
172 # "level = DEBUG" logs the route matched and routing variables.
173 # "level = DEBUG" logs the route matched and routing variables.
173 propagate = 0
174 propagate = 1
174
175
175 [logger_beaker]
176 [logger_beaker]
176 level = ERROR
177 level = DEBUG
177 handlers = console
178 handlers =
178 qualname = beaker.container
179 qualname = beaker.container
179 propagate = 0
180 propagate = 1
180
181
181 [logger_templates]
182 [logger_templates]
182 level = INFO
183 level = INFO
183 handlers = console
184 handlers =
184 qualname = pylons.templating
185 qualname = pylons.templating
185 propagate = 0
186 propagate = 1
186
187
187 [logger_rhodecode]
188 [logger_rhodecode]
188 level = DEBUG
189 level = DEBUG
189 handlers = console
190 handlers =
190 qualname = rhodecode
191 qualname = rhodecode
191 propagate = 0
192 propagate = 1
192
193
193 [logger_sqlalchemy]
194 [logger_sqlalchemy]
194 level = ERROR
195 level = INFO
195 handlers = console
196 handlers = console_sql
196 qualname = sqlalchemy.engine
197 qualname = sqlalchemy.engine
197 propagate = 0
198 propagate = 0
198
199
@@ -203,9 +204,15 b' propagate = 0'
203 [handler_console]
204 [handler_console]
204 class = StreamHandler
205 class = StreamHandler
205 args = (sys.stderr,)
206 args = (sys.stderr,)
206 level = NOTSET
207 level = INFO
207 formatter = color_formatter
208 formatter = color_formatter
208
209
210 [handler_console_sql]
211 class = StreamHandler
212 args = (sys.stderr,)
213 level = WARN
214 formatter = color_formatter_sql
215
209 ################
216 ################
210 ## FORMATTERS ##
217 ## FORMATTERS ##
211 ################
218 ################
@@ -217,4 +224,9 b' datefmt = %Y-%m-%d %H:%M:%S'
217 [formatter_color_formatter]
224 [formatter_color_formatter]
218 class=rhodecode.lib.colored_formatter.ColorFormatter
225 class=rhodecode.lib.colored_formatter.ColorFormatter
219 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
226 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
227 datefmt = %Y-%m-%d %H:%M:%S
228
229 [formatter_color_formatter_sql]
230 class=rhodecode.lib.colored_formatter.ColorFormatterSql
231 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
220 datefmt = %Y-%m-%d %H:%M:%S No newline at end of file
232 datefmt = %Y-%m-%d %H:%M:%S
@@ -142,57 +142,57 b' logview.pylons.util = #eee'
142 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ###
142 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ###
143 #########################################################
143 #########################################################
144 sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
144 sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
145 #sqlalchemy.db1.echo = False
145 sqlalchemy.db1.echo = True
146 #sqlalchemy.db1.pool_recycle = 3600
146 sqlalchemy.db1.pool_recycle = 3600
147 sqlalchemy.convert_unicode = true
147 sqlalchemy.convert_unicode = true
148
148
149 ################################
149 ################################
150 ### LOGGING CONFIGURATION ####
150 ### LOGGING CONFIGURATION ####
151 ################################
151 ################################
152 [loggers]
152 [loggers]
153 keys = root, routes, rhodecode, sqlalchemy,beaker,templates
153 keys = root, routes, rhodecode, sqlalchemy, beaker, templates
154
154
155 [handlers]
155 [handlers]
156 keys = console
156 keys = console, console_sql
157
157
158 [formatters]
158 [formatters]
159 keys = generic,color_formatter
159 keys = generic, color_formatter, color_formatter_sql
160
160
161 #############
161 #############
162 ## LOGGERS ##
162 ## LOGGERS ##
163 #############
163 #############
164 [logger_root]
164 [logger_root]
165 level = INFO
165 level = NOTSET
166 handlers = console
166 handlers = console
167
167
168 [logger_routes]
168 [logger_routes]
169 level = INFO
169 level = DEBUG
170 handlers = console
170 handlers =
171 qualname = routes.middleware
171 qualname = routes.middleware
172 # "level = DEBUG" logs the route matched and routing variables.
172 # "level = DEBUG" logs the route matched and routing variables.
173 propagate = 0
173 propagate = 1
174
174
175 [logger_beaker]
175 [logger_beaker]
176 level = ERROR
176 level = DEBUG
177 handlers = console
177 handlers =
178 qualname = beaker.container
178 qualname = beaker.container
179 propagate = 0
179 propagate = 1
180
180
181 [logger_templates]
181 [logger_templates]
182 level = INFO
182 level = INFO
183 handlers = console
183 handlers =
184 qualname = pylons.templating
184 qualname = pylons.templating
185 propagate = 0
185 propagate = 1
186
186
187 [logger_rhodecode]
187 [logger_rhodecode]
188 level = DEBUG
188 level = DEBUG
189 handlers = console
189 handlers =
190 qualname = rhodecode
190 qualname = rhodecode
191 propagate = 0
191 propagate = 1
192
192
193 [logger_sqlalchemy]
193 [logger_sqlalchemy]
194 level = ERROR
194 level = INFO
195 handlers = console
195 handlers = console_sql
196 qualname = sqlalchemy.engine
196 qualname = sqlalchemy.engine
197 propagate = 0
197 propagate = 0
198
198
@@ -203,9 +203,15 b' propagate = 0'
203 [handler_console]
203 [handler_console]
204 class = StreamHandler
204 class = StreamHandler
205 args = (sys.stderr,)
205 args = (sys.stderr,)
206 level = NOTSET
206 level = INFO
207 formatter = color_formatter
207 formatter = color_formatter
208
208
209 [handler_console_sql]
210 class = StreamHandler
211 args = (sys.stderr,)
212 level = WARN
213 formatter = color_formatter_sql
214
209 ################
215 ################
210 ## FORMATTERS ##
216 ## FORMATTERS ##
211 ################
217 ################
@@ -217,4 +223,9 b' datefmt = %Y-%m-%d %H:%M:%S'
217 [formatter_color_formatter]
223 [formatter_color_formatter]
218 class=rhodecode.lib.colored_formatter.ColorFormatter
224 class=rhodecode.lib.colored_formatter.ColorFormatter
219 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
225 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
226 datefmt = %Y-%m-%d %H:%M:%S
227
228 [formatter_color_formatter_sql]
229 class=rhodecode.lib.colored_formatter.ColorFormatterSql
230 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
220 datefmt = %Y-%m-%d %H:%M:%S No newline at end of file
231 datefmt = %Y-%m-%d %H:%M:%S
@@ -14,8 +14,35 b' COLORS = {'
14 'WARNING': CYAN, # level 30
14 'WARNING': CYAN, # level 30
15 'INFO': GREEN, # level 20
15 'INFO': GREEN, # level 20
16 'DEBUG': BLUE, # level 10
16 'DEBUG': BLUE, # level 10
17 'SQL' : YELLOW
17 }
18 }
18
19
20 def one_space_trim(s):
21 if s.find(" ") == -1:
22 return s
23 else:
24 s = s.replace(' ', ' ')
25 return one_space_trim(s)
26
27 def format_sql(sql):
28 sql = sql.replace('\n', '')
29 sql = one_space_trim(sql)
30 sql = sql\
31 .replace(',', ',\n\t')\
32 .replace('SELECT', '\n\tSELECT \n\t')\
33 .replace('UPDATE', '\n\tUPDATE \n\t')\
34 .replace('DELETE', '\n\tDELETE \n\t')\
35 .replace('FROM', '\n\tFROM')\
36 .replace('ORDER BY', '\n\tORDER BY')\
37 .replace('LIMIT', '\n\tLIMIT')\
38 .replace('WHERE', '\n\tWHERE')\
39 .replace('AND', '\n\tAND')\
40 .replace('LEFT', '\n\tLEFT')\
41 .replace('INNER', '\n\tINNER')\
42 .replace('INSERT', '\n\tINSERT')\
43 .replace('DELETE', '\n\tDELETE')
44 return sql
45
19 class ColorFormatter(logging.Formatter):
46 class ColorFormatter(logging.Formatter):
20
47
21 def __init__(self, *args, **kwargs):
48 def __init__(self, *args, **kwargs):
@@ -26,13 +53,31 b' class ColorFormatter(logging.Formatter):'
26 """
53 """
27 Changes record's levelname to use with COLORS enum
54 Changes record's levelname to use with COLORS enum
28 """
55 """
29
56
30 levelname = record.levelname
57 levelname = record.levelname
31 start = COLOR_SEQ % (COLORS[levelname])
58 start = COLOR_SEQ % (COLORS[levelname])
32 def_record = logging.Formatter.format(self, record)
59 def_record = logging.Formatter.format(self, record)
33 end = RESET_SEQ
60 end = RESET_SEQ
34
61
35 colored_record = start + def_record + end
62 colored_record = start + def_record + end
36 return colored_record
63 return colored_record
37
64
38 logging.ColorFormatter = ColorFormatter
65
66 class ColorFormatterSql(logging.Formatter):
67
68 def __init__(self, *args, **kwargs):
69 # can't do super(...) here because Formatter is an old school class
70 logging.Formatter.__init__(self, *args, **kwargs)
71
72 def format(self, record):
73 """
74 Changes record's levelname to use with COLORS enum
75 """
76
77 start = COLOR_SEQ % (COLORS['SQL'])
78 def_record = format_sql(logging.Formatter.format(self, record))
79 end = RESET_SEQ
80
81 colored_record = start + def_record + end
82 return colored_record
83
@@ -7,53 +7,22 b' def color_sql(sql):'
7 COLOR_SEQ = "\033[1;%dm"
7 COLOR_SEQ = "\033[1;%dm"
8 COLOR_SQL = YELLOW
8 COLOR_SQL = YELLOW
9 normal = '\x1b[0m'
9 normal = '\x1b[0m'
10 return COLOR_SEQ % COLOR_SQL + sql + normal
10 return COLOR_SEQ % COLOR_SQL + sql + normal
11
12 def one_space_trim(s):
13 if s.find(" ") == -1:
14 return s
15 else:
16 s = s.replace(' ', ' ')
17 return one_space_trim(s)
18
19 def format_sql(sql):
20 sql = color_sql(sql)
21 sql = sql.replace('\n', '')
22 sql = one_space_trim(sql)
23 sql = sql\
24 .replace(',', ',\n\t')\
25 .replace('SELECT', '\n\tSELECT \n\t')\
26 .replace('UPDATE', '\n\tUPDATE \n\t')\
27 .replace('DELETE', '\n\tDELETE \n\t')\
28 .replace('FROM', '\n\tFROM')\
29 .replace('ORDER BY', '\n\tORDER BY')\
30 .replace('LIMIT', '\n\tLIMIT')\
31 .replace('WHERE', '\n\tWHERE')\
32 .replace('AND', '\n\tAND')\
33 .replace('LEFT', '\n\tLEFT')\
34 .replace('INNER', '\n\tINNER')\
35 .replace('INSERT', '\n\tINSERT')\
36 .replace('DELETE', '\n\tDELETE')
37 return sql
38
39
11
40 class TimerProxy(ConnectionProxy):
12 class TimerProxy(ConnectionProxy):
41
13
42 def __init__(self):
14 def __init__(self):
43 super(TimerProxy, self).__init__()
15 super(TimerProxy, self).__init__()
44 self.logging_name = 'timerProxy'
16 self.logging_name = 'timerProxy'
45 self.log = log.instance_logger(self, True)
17 self.log = log.instance_logger(self, True)
46
18
47 def cursor_execute(self, execute, cursor, statement, parameters, context, executemany):
19 def cursor_execute(self, execute, cursor, statement, parameters,
48
20 context, executemany):
21
49 now = time.time()
22 now = time.time()
50 try:
23 try:
51 self.log.info(">>>>> STARTING QUERY >>>>>")
24 self.log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
52 return execute(cursor, statement, parameters, context)
25 return execute(cursor, statement, parameters, context)
53 finally:
26 finally:
54 total = time.time() - now
27 total = time.time() - now
55 try:
28 self.log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total))
56 self.log.info(format_sql("Query: %s" % statement % parameters))
57 except TypeError:
58 self.log.info(format_sql("Query: %s %s" % (statement, parameters)))
59 self.log.info("<<<<< TOTAL TIME: %f <<<<<" % total)
General Comments 0
You need to be logged in to leave comments. Login now