Difference between revisions of "Apache LogFormat"

From Noah.org
Jump to: navigation, search
m
Line 1: Line 1:
 
[[Category:Engineering]]
 
[[Category:Engineering]]
This is how I set my Apache LogFormat. This includes a lot of extra info, but my traffic volume is low. Even on large volume sites, I found Apache logging to add fairly low overhead and better logs are almost always worth their weight.
+
This is how I configure my Apache LogFormat. This includes a lot of extra info that a high-traffic site might not want to log, but I found Apache's logging facility to be very efficient. The extra log info has a very log overhead. This configuration eliminates log messages from favicon.ico requests; server status checks (libwww-perl); and internal connection checks (internal dummy connection).
  
 
<pre>
 
<pre>
Line 7: Line 7:
 
# %l Remote logname (from identd, if supplied). This will return a dash unless mod_ident is present and IdentityCheck is set On.
 
# %l Remote logname (from identd, if supplied). This will return a dash unless mod_ident is present and IdentityCheck is set On.
 
# %u Remote user (from auth; may be bogus if return status (%s) is 401)
 
# %u Remote user (from auth; may be bogus if return status (%s) is 401)
# %t Time the request was received (standard english format)
+
# %t Time the request was received (standard English format)
 
# %r First line of request
 
# %r First line of request
 
# %>s status. For requests that got internally redirected, this is the status of the *original* request --- %>s  for the last.
 
# %>s status. For requests that got internally redirected, this is the status of the *original* request --- %>s  for the last.
Line 15: Line 15:
 
# %{Foorbar}C The contents of cookie Foobar in the request sent to the server.
 
# %{Foorbar}C The contents of cookie Foobar in the request sent to the server.
 
# %P The process ID of the child that serviced the request.
 
# %P The process ID of the child that serviced the request.
# %D The time taken to serve the request, in microseconds.
+
# %D The microseconds of time taken to serve the request.
 
     LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %P %D" vcombinedwithPD
 
     LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %P %D" vcombinedwithPD
  
 
     SetEnvIf Request_URI "^/favicon\.ico$" dontlog
 
     SetEnvIf Request_URI "^/favicon\.ico$" dontlog
 +
    SetEnvIf User-Agent "libwww-perl.*" dontlog
 
     SetEnvIf User-Agent ".*internal dummy connection.*" dontlog
 
     SetEnvIf User-Agent ".*internal dummy connection.*" dontlog
 
     CustomLog logs/access_log vcombinedwithPD env=!dontlog
 
     CustomLog logs/access_log vcombinedwithPD env=!dontlog
 
</pre>
 
</pre>

Revision as of 11:48, 28 June 2010

This is how I configure my Apache LogFormat. This includes a lot of extra info that a high-traffic site might not want to log, but I found Apache's logging facility to be very efficient. The extra log info has a very log overhead. This configuration eliminates log messages from favicon.ico requests; server status checks (libwww-perl); and internal connection checks (internal dummy connection).

# %V The server name according to the UseCanonicalName setting. Useful for virtual hosting servers.
# %h Remote host
# %l Remote logname (from identd, if supplied). This will return a dash unless mod_ident is present and IdentityCheck is set On.
# %u Remote user (from auth; may be bogus if return status (%s) is 401)
# %t Time the request was received (standard English format)
# %r First line of request
# %>s status. For requests that got internally redirected, this is the status of the *original* request --- %>s  for the last.
# %b Size of response in bytes, excluding HTTP headers. In CLF format, i.e.  a '-' rather than a 0 when no bytes are sent.
# %{Referer}i The contents of Foobar: header line(s) in the request sent to the server.
# %{User-Agent}i 
# %{Foorbar}C The contents of cookie Foobar in the request sent to the server.
# %P The process ID of the child that serviced the request.
# %D The microseconds of time taken to serve the request.
    LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %P %D" vcombinedwithPD

    SetEnvIf Request_URI "^/favicon\.ico$" dontlog
    SetEnvIf User-Agent "libwww-perl.*" dontlog
    SetEnvIf User-Agent ".*internal dummy connection.*" dontlog
    CustomLog logs/access_log vcombinedwithPD env=!dontlog