[PATCH] base: add request time to footer
Thomas De Schampheleire
patrickdepinguin at gmail.com
Tue Mar 31 11:00:20 EDT 2015
# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1427813112 -7200
# Tue Mar 31 16:45:12 2015 +0200
# Node ID 66accc3fb9a93d6e704177c80ea7500f1a34f02b
# Parent de5eaaad471f2c746a1b1fed0022a483284d243c
base: add request time to footer
Currently, the time to handle a request is only shown in the log, while it is
more readily useful when part of the page itself. Use a simple string
substitution to replace the time before finalizing the request.
diff --git a/kallithea/lib/middleware/wrapper.py b/kallithea/lib/middleware/wrapper.py
--- a/kallithea/lib/middleware/wrapper.py
+++ b/kallithea/lib/middleware/wrapper.py
@@ -40,10 +40,12 @@ class RequestWrapper(object):
def __call__(self, environ, start_response):
start = time.time()
try:
- return self.application(environ, start_response)
+ response = self.application(environ, start_response)
finally:
log = logging.getLogger('kallithea.' + self.__class__.__name__)
+ total = time.time() - start
log.info('IP: %s Request to %s time: %.3fs' % (
_get_ip_addr(environ),
- safe_unicode(_get_access_path(environ)), time.time() - start)
+ safe_unicode(_get_access_path(environ)), total)
)
+ return ''.join(response).replace('%##kallithea_request_time##%', '%.3fs' % total)
diff --git a/kallithea/templates/base/base.html b/kallithea/templates/base/base.html
--- a/kallithea/templates/base/base.html
+++ b/kallithea/templates/base/base.html
@@ -29,6 +29,7 @@
%if c.issues_url:
– <a href="${c.issues_url}" target="_blank">${_('Support')}</a>
%endif
+ – Request time: %##kallithea_request_time##%
</p>
</div>
</div>
More information about the kallithea-general
mailing list