Issue #1019 resolved

Allow logging host name in the access log when using multiple virtual domains

Anonymous created an issue

If you have a webapp that serves multiple virtual hosts, the distinction which page was served for which host can't be recorded in the logfile, since there is currently no way to have the request.headers['host'] logged in access.log. For that, I made a one line addition to, in the atoms dict, I added an entry 'o' which allows one to log the Host the request came from.

With the patch, it becomes possible to do this:

{{{ log=app.log log.access_log_format='%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(o)s'

Note the %(o)s at the end, which logs the Host


The patch, against trunk #2689:

{{{ --- 2010-08-21 11:37:19.000000000 +0200 +++ 2010-08-21 11:37:41.000000000 +0200 @@ -217,6 +217,7 @@ 'b': dict.get(outheaders, 'Content-Length', '') or "-", 'f': dict.get(inheaders, 'Referer', ''), 'a': dict.get(inheaders, 'User-Agent', ''), + 'o': dict.get(inheaders, 'Host', '-'), } for k, v in atoms.items(): if isinstance(v, unicode): }}}

Reported by

Comments (3)

  1. Anonymous

    Ah, to clarify:

    In my application, which serves hundreds to thousands of virtual domains, it will be undesirable to have so much logfiles lying around (and being open and written to simultaneously). I plan to do the log analysis later, based on selective extraction of log lines using the virtualhostname.

    Furthermore, I do not propose a change to the logging format, only the ''possibility'' of using the virtual hostname in the log, if someone desires so (this requires explicit redefinition of app.log.access_log_format, if you leave that at the default you'll get a perfectly conforming CLF, even with my patch in place).

    Thinking of it, it would be nice if access() could log any field from inheaders or outheaders, not just the pre-canned ones. But that's an exercise for later ;-)

  2. Log in to comment