Chapter 7. Logging
The escape sequences used in the Common Log Format
%h
The client’s hostname
%l
If the web server was doing IDENT (RFCnnnn) lookups then the returned userid
would be here.
%u
If the client had authenticated as a particular user for this request the userid
would be recorded here. We discuss authentication in detail in the Section called
Access control by client identity in Chapter 10.
%t
The time of the request.
%r
The first line of the query.
%>s
The status code finally returned to the client. There is a subtle difference be-
tween %s and %>s. In most cases they are identical. In cases where the URL gets
remapped then %s gives the status code of the initial lookup and %>s the code
of the final lookup (and the code passed back to the client).
%b
The number of data bytes (i.e. excluding the headers) sent back to the client in
the case of successful completion..
Named formats
A common requirement is for all virtual hosts to log in the same format. To assist
with this it is possible to name a format definition and to then refer to the format’s
name in the CustomLog line.
LogFormat "%h %l %u %t \"%r\" %>s %b" clf
<VirtualHost *>
ServerName chalk.dept.cam.ac.uk
DocumentRoot /var/www/CHALK
CustomLog logs/chalk_log clf
</VirtualHost>
<VirtualHost *>
ServerName cheese.dept.cam.ac.uk
DocumentRoot /var/www/CHEESE
CustomLog logs/cheese_log clf
</VirtualHost>
Figure 7-13. Using named log formats with virtual hosts
Logging headers
One very useful escape code is %{fubar}i which will log the value of incoming
header fubar. We could use this as %{Host}i to record the queried Host header, for
example, to check our virtual hosting was working as expected.
56
Commenti su questo manuale