diff options
author | Michiel Overtoom <motoom@xs4all.nl> | 2013-03-30 23:39:24 +0100 |
---|---|---|
committer | Michiel Overtoom <motoom@xs4all.nl> | 2013-03-30 23:39:24 +0100 |
commit | cfddccbe2f7ec1491acc098323a2e976eae57740 (patch) | |
tree | 4a195fc0a37669f159563fe2fc0d59126788268e | |
parent | 5229f2fe9d096e3af9e354976e7e9422d392bf06 (diff) | |
download | cherrypy-cfddccbe2f7ec1491acc098323a2e976eae57740.tar.gz |
Custom logging: hostname
-rw-r--r-- | cherrypy/_cplogging.py | 1 | ||||
-rw-r--r-- | cherrypy/test/test_logging.py | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/cherrypy/_cplogging.py b/cherrypy/_cplogging.py index cecbcd50..9d8bf8c5 100644 --- a/cherrypy/_cplogging.py +++ b/cherrypy/_cplogging.py @@ -242,6 +242,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 e01e99c6..973e5b0f 100644 --- a/cherrypy/test/test_logging.py +++ b/cherrypy/test/test_logging.py @@ -106,6 +106,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() |