Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Logging

Apache provides for logging just about any information you might be interested in from Web accesses. There are two standard log files that are generated when you run your Apache server—access_log and error_log. All logs except for the error_log (by default, this is just the access_log) are generated in a format specified by the CustomLog and LogFormat directives. These directives appear in your httpd.conf file.

A new log format can be defined with the LogFormat directive:

LogFormat "%h %l %u %t \"%r\" %>s %b" common

The common log format is a good starting place for creating your own custom log formats. Note that most of the log analysis tools available will assume that you are using the common log format or the combined log format, both of which are defined in the default configuration files.

The following variables are available for LogFormat statements:

%a Remote IP address.
%A Local IP address.
%b Bytes sent, excluding HTTP headers. This is shown in CLF format. For a request without any data content, a "-" will be shown instead of 0.
%B Bytes sent, excluding HTTP headers.
%{VARIABLE}e The contents of the environment variable VARIABLE.
%f Filename.
%h Remote host.
%H Request protocol.
%{HEADER}i The contents of HEADER; header line(s) in the request sent to the server.
%l Remote logname (from identd, if supplied).
%m Request method.
%{NOTE}n The contents of note NOTE from another module.
%{HEADER}o The contents of HEADER; header line(s) in the reply.
%p The canonical port of the server serving the request.
%P The process ID of the child that serviced the request.
%q The contents of the query string, prepended with a ? character. If there is no query string this will evaluate to an empty string.
%r First line of request.
%s Status. For requests that were internally redirected, this is the status of the original request—%>s for the last.
%t Time, in common log format time format.
%{format}t The time, in the form given by format, which should be in strftime(3) format. See the section Basic SSI Directives for a complete list of available formatting options.
%T The time taken to serve the request, in seconds.
%u Remote user from auth; may be bogus if return status (%s) is 401.
%U The URL path requested.
%V The server name according to the UseCanonicalName directive.
%v The canonical ServerName of the server serving the request.

In each variable, you can put a conditional in front of the variable that will determine whether the variable is displayed. If it is not displayed, - will be displayed instead. These conditionals are in the form of a list of numerical return values. For example, %!401u will display the value of REMOTE_USER unless the return code is 401.

You can then specify the location and format of a log file using the CustomLog directive:

CustomLog logs/access_log common

If it is not specified as an absolute path, the location of the log file is assumed to be relative to the ServerRoot.

Share ThisShare This

Informit Network