Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

ghost opened this issue Aug 21, 2010 · 3 comments


Copy link

ghost commented Aug 21, 2010

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, 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.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

Copy link

ghost commented Aug 21, 2010

Original comment by Anonymous:

In that case the log doesn't respect the CLF spec I'm afraid.

I'd rather vhosts to log each in their own log files.

Copy link

ghost commented Aug 21, 2010

Original comment by 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 ;-)

Copy link

ghost commented Sep 14, 2014

Original comment by Jason R. Coombs (Bitbucket: jaraco, GitHub: jaraco):

Fixed in 20690b4bd948 (Pull Request #38)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

0 participants