Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-15-2006, 03:47 PM   #1
Registered: Dec 2005
Posts: 47

Rep: Reputation: 16
Apache 2.0 | logging | Recording the host name in the log files

Is there any way to record the Host name requested in the access log. (The site has many subdomains and do not want each one to have its own log file.)

I've tried this:

LogFormat "%h %l %u %t \"%r\" \"%{HTTP_HOST}\" %>s %b" commonwh

but for some reason this doesn't work. (On the other hand the %{Referer} variable works - why not %{HTTP_HOST}?).

Thank you.
Old 02-16-2006, 03:43 PM   #2
Senior Member
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
There sure is, and honestly this is an RTFM issue. However here is the solution, borrowed from my kim.httpd.conf:

LogFormat "%h %l %u %t %v \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" myLogFormat
CustomLog /var/awstats/kim/log/kim.log myLogFormat
%h = host (which is what you're looking to log)
$l = remote log name
%u = username (http authentication, if used)
%t = time of request
%v = the canonical server name (if UseCanonicalName defined gets logged, otherwise a - is substituted)
\"%r\" = the query, method, and http rev (e.g., get /foo.html http/1.1)
%>s = HTTP transfer status code (what it sets in the response header)
%b = bytes transferred
\"%{Referer}i\" = the referrer variable (the site linking to you)
\"%{User-agent}i\" = the user agent variable (the requestor's reported user agent)

myLogFormat = what I named that logfile spec

This line:
CustomLog /var/awstats/kim/log/kim.log myLogFormat
tells the server to write the log to /var/awstats/kim/log/kim.log, and use the myLogFormat spec defined above

Last edited by KimVette; 02-16-2006 at 03:51 PM.
Old 02-16-2006, 04:06 PM   #3
Registered: Dec 2005
Posts: 47

Original Poster
Rep: Reputation: 16
Actually no, this is not a RTFM situation (or at least it's not obviously there). If you read my question, I wanted the host name that was requested by the client not the client's host name / ip.

Well anyway a little messing around and I found the solution. If anyone else needs it:

1. you need an "i" after these types of "long" variables (as with the others)
2. its not %{HTTP_HOST} as in mod_rewrite conditions, but rather %{Host} (lucky guess

So it should be

LogFormat "%h %l %u %t \"%r\" \"%{Host}i\" %>s %b" commonwh

1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Browser Log Files soulestream Linux - Software 1 12-14-2005 03:59 AM
multiple log files in apache Red Squirrel Linux - Software 1 09-27-2005 01:42 AM
pppd logging to /var/log/ppp.log problem mrtwice Linux - Software 1 01-10-2004 06:38 PM
Question on Apache Log Files JLDixon Linux - Software 1 10-12-2003 12:03 PM
Can log files be time stamped? (such as FTP login and transfer log files) bripage Linux - Networking 6 08-08-2002 11:55 PM

All times are GMT -5. The time now is 03:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration