Skip to content

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

Description

Originally reported by: Anonymous


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 _cplogging.py/access(), 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:

--- _cplogging.py.2689  2010-08-21 11:37:19.000000000 +0200
+++ _cplogging.py   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 motoom@xs4all.nl


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions