Customizing apache web logs

Custom formats for apache web logs, to record more information or to make them easier to read.


%h The remote host
%l The remote logname (usually just “-”)
%u The authenticated user (if any)
%t The time of the access
\”%r\” The first line of the request
%>s The final status of the request
%b The size of the server’s response, in bytes
\”%{Referer}i\” The referrer URL, taken from the request’s headers
\”%{User-Agent}i\” The user agent, taken from the request’s headers

Apache’s “LogFormat” directive is what lets you define your own access log setup. Let’s look at how that directive would be used to define the combined log format (CLF):

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined

That first argument, in quotes, is the string that describes the log format. The last argument, “combined”, gives a nickname to the format that can be used by CustomLog later on.

That format string contains a bunch of placeholders that describe the data to be included in the log. That first one, for example, is “%h” and represents the IP address of the visitor (the identifier for their host). A bit further on, “%t” represents the time of the request.

Comments are closed.