def __call__(self, report_time, frame=None): elapsed = report_time - self.start request = self.request lines = list() if not self.logged_first: if request.method == 'POST': postdata = {} postdata.update(request.POST) for key in self.tween.hide_post_vars: if key in postdata: postdata[key] = Hidden() lines.append('post: %s' % pformat(postdata)) self.logged_first = True if frame is not None: limit = self.tween.frame_limit if limit > 0: tb = StringIO() tb.write('Traceback:\n') print_stack(frame, limit=limit, file=tb) lines.append(tb.getvalue()) del frame log = self.tween.log logger_name = "slowlog.{0}".format(request.matched_route.name) page_logger = logging.getLogger(logger_name) map(page_logger.addHandler, log.handlers) lead = "{0} on {1}".format(request.method, request.url) page_logger.warn("{0}\n{1}".format(lead, '\n'.join(lines)))
def __call__(self, report_time, frame=None): elapsed = report_time - self.start env = self.environ url = construct_url(env) lines = ['request: %s %s' % (env.get('REQUEST_METHOD'), url)] if not self.logged_first: env = env.copy() for key in self.app.hide_env: if key in env: env[key] = Hidden() lines.append('environ: %s' % pformat(env)) self.logged_first = True if frame is not None: limit = self.app.frame_limit if limit > 0: tb = StringIO() tb.write('Traceback:\n') print_stack(frame, limit=limit, file=tb) lines.append(tb.getvalue()) del frame log = self.app.log log.warning("Thread %s: Started on %.1f; " "Running for %.1f secs; %s", self.ident, self.start, elapsed, '\n'.join(lines))
def test_without_barrier(self): frame = sys._getframe() f = StringIO() self._call(frame, 100, f) lines = f.getvalue().splitlines() self.assertGreater(len(lines), 2) self.assertLess(len(lines), 100)
def __call__(self, report_time, frame=None): elapsed = report_time - self.start request = self.request lines = ['request: %s %s' % (request.method, request.url)] if not self.logged_first: if request.method == 'POST': postdata = {} postdata.update(request.POST) for key in self.tween.hide_post_vars: if key in postdata: postdata[key] = Hidden() lines.append('post: %s' % pformat(postdata)) self.logged_first = True if frame is not None: limit = self.tween.frame_limit if limit > 0: tb = StringIO() tb.write('Traceback:\n') print_stack(frame, limit=limit, file=tb) lines.append(tb.getvalue()) del frame log = self.tween.log msg = '\n'.join(lines) log.warning("Thread %s: Started on %.1f; " "Running for %.1f secs; %s", self.ident, self.start, elapsed, msg)
def test_with_barrier(self): frames = [] def func3(): frames.append(sys._getframe()) def func2(): func3() def func1(): __slowlog_barrier__ = True func2() func1() frame = frames[0] f = StringIO() self._call(frame, 100, f) lines = f.getvalue().splitlines() self.assertEqual(len(lines), 6) match = self.assertRegexpMatches match(lines[0], r' File ".*/test_exc.py", line \d+, in func1$') match(lines[2], r' File ".*/test_exc.py", line \d+, in func2$') match(lines[4], r' File ".*/test_exc.py", line \d+, in func3$')