summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-09-13 22:54:55 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-09-13 22:54:55 -0400
commite2529b59a49cb7d8eb3851af9e151f4b583c95a4 (patch)
tree62a8eacdca7bcdd8fd4e0b7b70ebea42b0671e08
parent97a5b9591916e680c0d9e7da8c3d44eef4d3433c (diff)
parentcfddccbe2f7ec1491acc098323a2e976eae57740 (diff)
downloadcherrypy-e2529b59a49cb7d8eb3851af9e151f4b583c95a4.tar.gz
Merged in MichielOvertoom/cherrypycustomlogging (pull request #38)
Custom logging: hostname and testcase
-rw-r--r--cherrypy/_cplogging.py1
-rw-r--r--cherrypy/test/test_logging.py20
2 files changed, 21 insertions, 0 deletions
diff --git a/cherrypy/_cplogging.py b/cherrypy/_cplogging.py
index af9e032a..554fd7ef 100644
--- a/cherrypy/_cplogging.py
+++ b/cherrypy/_cplogging.py
@@ -256,6 +256,7 @@ class LogManager(object):
'b': dict.get(outheaders, 'Content-Length', '') or "-",
'f': dict.get(inheaders, 'Referer', ''),
'a': dict.get(inheaders, 'User-Agent', ''),
+ 'o': dict.get(inheaders, 'Host', '-'),
}
if py3k:
for k, v in atoms.items():
diff --git a/cherrypy/test/test_logging.py b/cherrypy/test/test_logging.py
index 9375494f..0c029ad7 100644
--- a/cherrypy/test/test_logging.py
+++ b/cherrypy/test/test_logging.py
@@ -105,6 +105,26 @@ class AccessLogTests(helper.CPWebCase, logtest.LogCase):
self.assertLog(-1, '] "GET %s/as_yield HTTP/1.1" 200 - "" ""'
% self.prefix())
+ def testCustomLogFormat(self):
+ '''Test a customized access_log_format string,
+ which is a feature of _cplogging.LogManager.access() '''
+
+ original_logformat = cherrypy._cplogging.LogManager.access_log_format
+ cherrypy._cplogging.LogManager.access_log_format = \
+ '{h} {l} {u} {t} "{r}" {s} {b} "{f}" "{a}" {o}' \
+ if py3k else \
+ '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(o)s'
+
+ self.markLog()
+ self.getPage("/as_string", headers=[('Referer', 'REFERER'),
+ ('User-Agent', 'USERAGENT'),
+ ('Host', 'HOST')])
+ self.assertLog(-1, '%s - - [' % self.interface())
+ self.assertLog(-1, '] "GET /as_string HTTP/1.1" '
+ '200 7 "REFERER" "USERAGENT" HOST')
+
+ cherrypy._cplogging.LogManager.access_log_format = original_logformat
+
def testEscapedOutput(self):
# Test unicode in access log pieces.
self.markLog()