1N/A<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1N/A<
TITLE>Apache module mod_log_config</
TITLE>
1N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) --> 1N/A<
H1 ALIGN="CENTER">Module mod_log_config</
H1>
1N/Aand is compiled in by default in Apache 1.2. mod_log_config replaces
1N/Amod_log_common in Apache 1.2. Prior to version 1.2, mod_log_config was
1N/Aan optional module. It provides for logging of the requests made to
1N/Athe server, using the Common Log Format or a user-specified format.
1N/AThree directives are provided by this module: <
CODE>TransferLog</
CODE>
1N/Ato create a log file, <
CODE>LogFormat</
CODE> to set a custom format,
1N/Aand <
CODE>CustomLog</
CODE> to define a log file and format in one go.
1N/AThe <
CODE>TransferLog</
CODE> and <
CODE>CustomLog</
CODE> directives can
1N/Abe used multiple times in each server to cause each request to be
1N/Alogged to multiple files.
1N/A<
H3>Compatibility notes</
H3>
1N/A<
LI>This module is based on mod_log_config distributed with
1N/Aprevious Apache releases, now updated to handle multiple logs.
1N/AThere is now no need to re-configure Apache to use configuration log
1N/A<
LI>The module also implements the <
CODE>CookieLog</
CODE> directive,
1N/Aused to log user-tracking information created by <
A 1N/A<
CODE>CookieLog</
CODE> is deprecated, and a <
CODE>CustomLog</
CODE>
1N/Ashould be defined to log user-tracking information instead.
1N/A<
LI>As of Apache 1.3.5, this module allows conditional logging
1N/Abased upon the setting of environment variables. That is,
1N/Ayou can control whether a request should be logged or not
1N/Abased upon whether an arbitrary environment variable is
1N/Adefined or not. This is settable on a <
EM>per</
EM>-logfile
1N/A<
LI>Beginning with Apache 1.3.5, the mod_log_config module has
1N/Aalso subsumed the <
CODE>RefererIgnore</
CODE> directive from
1N/Aof <
CODE>RefererIgnore</
CODE> is deprecated, and should be
1N/Areplaced by combinations of
1N/Aand environment variable controlled <
CODE>CustomLog</
CODE>
1N/A<
H2>Log File Formats</
H2>
1N/AUnless told otherwise with <
TT>LogFormat</
TT> the log files created by
1N/A<
TT>TransferLog</
TT> will be in standard "Common Log Format"
1N/A(CLF). The contents of each line in a CLF file are explained
1N/Abelow. Alternatively, the log file can be customized (and if multiple
1N/Alog files are used, each can have a different format). Custom formats
1N/Aare set with <
CODE>LogFormat</
CODE> and <
CODE>CustomLog</
CODE>.
1N/A<
H3>Common Log Format</
H3>
1N/AThe Common Log Format (CLF) file contains a separate line for each
1N/Arequest. A line is composed of several tokens separated by spaces:
1N/Ahost ident authuser date request status bytes
1N/AIf a token does not have a value then it is represented by a hyphen (-).
1N/AThe meanings and values of these tokens are as follows:
1N/A<
DD>The fully-qualified domain name of the client, or its IP number if the
1N/Aname is not available.
1N/A<
DD>If <
A HREF="core.html#identitycheck">IdentityCheck</
A> is enabled and the
1N/Aclient machine runs identd, then this is the identity information reported
1N/A<
DD>If the request was for an password protected document, then this is
1N/Athe userid used in the request.
1N/A<
DD>The date and time of the request, in the following format:
1N/A<
DL><
DD><
BLOCKQUOTE><
CODE> date = [
day/
month/
year:hour:minute:second zone] <
BR>
1N/Azone = (`+' | `-') 4*digit</
CODE></
BLOCKQUOTE></
DL>
1N/A<
DD>The request line from the client, enclosed in double quotes
1N/A(<
CODE>"</
CODE>).
1N/A<
DD>The three digit status code returned to the client.
1N/A<
DD>The number of bytes in the object returned to the client, not including
1N/A<
H3><
A NAME="formats">Custom Log Formats</
A></
H3>
1N/AThe format argument to the <
CODE>LogFormat</
CODE> and
1N/A<
CODE>CustomLog</
CODE> is a string. This string is logged to the log
1N/Afile for each request. It can contain literal characters copied into
1N/Athe log files, and `%' directives which are replaced in the log file
1N/Aby the values as follows:
1N/A%
...b: Bytes sent, excluding HTTP headers.
1N/A%...{FOOBAR}e: The contents of the environment variable FOOBAR
1N/A%...{Foobar}i: The contents of Foobar: header line(s) in the request
1N/A%
...l: Remote logname (from identd, if supplied)
1N/A%...{Foobar}n: The contents of note "Foobar" from another module.
1N/A%...{Foobar}o: The contents of Foobar: header line(s) in the reply.
1N/A%
...p: The canonical Port of the server serving the request
1N/A%
...P: The process ID of the child that serviced the request.
1N/A%
...s: Status. For requests that got internally redirected, this
1N/A is status of the *original* request --- %...>s for the last.
1N/A%
...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.
%
...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 canonical ServerName of the server serving the request.
The `...' can be nothing at all (<
EM>
e.g.</
EM>, <
CODE>"%h %u %r %s %b"</
CODE>), or it can
indicate conditions for inclusion of the item (which will cause it
to be replaced with `-' if the condition is not met). Note that
there is no escaping performed on the strings from %r, %
...i and
%
...o; some with long memories may remember that I thought this was
a bad idea, once upon a time, and I'm still not comfortable with
it, but it is difficult to see how to `do the right thing' with all
of `%
..i', unless we URL-escape everything and break with CLF.
The forms of condition are a list of HTTP status codes, which may
or may not be preceded by `!'. Thus, `%400,501{User-agent}i' logs
User-agent: on 400 errors and 501 errors (Bad Request, Not
Implemented) only; `%!200,304,302{Referer}i' logs Referer: on all
requests which did <
STRONG>not</
STRONG> return some sort of normal status.
Note that the common log format is defined by the string <
CODE>"%h %l
%u %t \"%r\" %s %b"</
CODE>, which can be used as the basis for
extending for format if desired (<
EM>
e.g.</
EM>, to add extra fields at the end).
NCSA's
extended/
combined log format would be <
CODE>"%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""</
CODE>.
Note that the canonical <
A HREF="core.html#servername">ServerName</
A>
and <
A HREF="core.html#port">Port</
A> of the server serving the request
are used for <
CODE>%v</
CODE> and <
CODE>%p</
CODE> respectively. This
happens regardless of the
<
A HREF="core.html#usecanonicalname">UseCanonicalName</
A> setting because
otherwise log analysis programs would have to duplicate the entire
vhost matching algorithm in order to decide what host really served
<
H2>Using Multiple Log Files</
H2>
The <
CODE>TransferLog</
CODE> and <
CODE>CustomLog</
CODE> directives can
be given more than once to log requests to multiple log files. Each
request will be logged to all the log files defined by either of these
<
H3>Use with Virtual Hosts</
H3>
If a <VirtualHost> section does not contain any
<
TT>TransferLog</
TT> or <
TT>CustomLog</
TT> directives, the
logs defined for the main server will be used. If it does
contain one or more of these directives, requests serviced by
this virtual host will only be logged in the log files defined
within its definition, not in any of the main server's log files.
<
H2>Security Considerations</
H2>
document for details on why your security could be compromised if the
directory where logfiles are stored is writable by anyone other than
the user that starts the server.
<
LI><
A HREF="#cookielog">CookieLog</
A>
<
LI><
A HREF="#customlog">CustomLog</
A>
<
LI><
A HREF="#customlog-conditional">CustomLog (conditional)</
A>
<
LI><
A HREF="#logformat">LogFormat</
A>
<
LI><
A HREF="#refererignore">RefererIgnore</
A>
<
LI><
A HREF="#transferlog">TransferLog</
A>
<
H2><
A NAME="cookielog">CookieLog</
A></
H2>
<!--%plaintext <?INDEX {\tt CookieLog} directive> --> ><
STRONG>Syntax:</
STRONG></
A> CookieLog <
EM>filename</
EM><
BR>
><
STRONG>Context:</
STRONG></
A> server config, virtual host<
BR>
><
STRONG>Module:</
STRONG></
A> mod_cookies<
BR>
><
STRONG>Compatibility:</
STRONG></
A> Only available in Apache 1.2 and above<
P>
The CookieLog directive sets the filename for logging of cookies.
The filename is relative to the <
AHREF="core.html#serverroot">ServerRoot</
A>. This directive is included
only for compatibility with
<
H2><
A NAME="customlog">CustomLog</
A></
H2>
><
STRONG>Syntax:</
STRONG></
A> CustomLog <
EM>file-pipe</
EM>
<
EM>format-or-nickname</
EM><
BR>
><
STRONG>Context:</
STRONG></
A> server config, virtual host<
BR>
><
STRONG>Status:</
STRONG></
A> Base<
BR>
><
STRONG>Compatibility:</
STRONG></
A> Nickname only available in Apache 1.3
><
STRONG>Module:</
STRONG></
A> mod_log_config
The first argument is the filename to which log records should be
exactly like the argument to
><
SAMP>TransferLog</
SAMP></
A>;
that is, it is either a full path or relative to the current
The format argument specifies a format for each line of the log file.
The options available for the format are exactly the same as for
the argument of the <
TT>LogFormat</
TT> directive. If the format
includes any spaces (which it will do in almost all cases) it
should be enclosed in double quotes.
Instead of an actual format string, you can use a format nickname defined with
><
SAMP>LogFormat</
SAMP></
A>
<
H2><
A NAME="customlog-conditional">CustomLog (conditional)</
A></
H2>
><
STRONG>Syntax:</
STRONG></
A> CustomLog <
EM>file-pipe</
EM>
<
EM>format-or-nickname</
EM>
env=[!]<
EM>environment-variable</
EM><
BR>
><
STRONG>Context:</
STRONG></
A> server config, virtual host<
BR>
><
STRONG>Status:</
STRONG></
A> Base<
BR>
><
STRONG>Compatibility:</
STRONG></
A> Only available in Apache 1.3.5
><
STRONG>Module:</
STRONG></
A> mod_log_config
The behaviour of this form of the <
SAMP>CustomLog</
SAMP> directive is almost
identical to the <
A HREF="#customlog">standard <
CODE>CustomLog</
CODE></
A>
directive. The difference is that the '<
CODE>env=</
CODE>' clause controls
whether a particular request will be logged in the specified file or
not. If the specified environment variable is set for the
request (or is not set, in the case of a '<
CODE>env=!<
EM>name</
EM></
SAMP>'
clause), then the request will be logged.
Environment variables can be set on a <
EM>per</
EM>-request basis
if you don't want to record requests for all GIF images on
your server in a separate logfile but not your main log, you
SetEnvIf Request_URI \.gif$ gif-image
<
H2><
A NAME="logformat">LogFormat</
A></
H2>
<!--%plaintext <?INDEX {\tt LogFormat} directive> --> ><
STRONG>Syntax:</
STRONG></
A> LogFormat <
EM>format</
EM> [<
EM>nickname</
EM>]
><
STRONG>Default:</
STRONG></
A> <
CODE>LogFormat "%h %l %u %t \"%r\"
><
STRONG>Context:</
STRONG></
A> server config, virtual host<
BR>
><
STRONG>Status:</
STRONG></
A> Base<
BR>
><
STRONG>Compatibility:</
STRONG></
A> Nickname only available in Apache 1.3
><
STRONG>Module:</
STRONG></
A> mod_log_config
This sets the format of the default logfile named by the
><
SAMP>TransferLog</
SAMP></
A>
directive . See the section on
<
A HREF="#formats">Custom Log Formats</
A> for details on the format
If you include a nickname for the format on the directive line, you can
use it in other <
SAMP>LogFormat</
SAMP> and
<
A HREF="#customlog"><
SAMP>CustomLog</
SAMP></
A>
directives rather than repeating the entire format string.
<
SAMP>LogFormat</
SAMP> directive which defines a nickname <
STRONG>does
nothing else</
STRONG> -- that is, it <
EM>only</
EM> defines the nickname,
it doesn't actually apply the format and make it the default.
<
H2><
A NAME="refererignore">RefererIgnore</
A></
H2>
><
STRONG>Syntax:</
STRONG></
A> RefererIgnore <
EM>string string ...</
EM><
BR>
><
STRONG>Context:</
STRONG></
A> server config, virtual host<
BR>
><
STRONG>Status:</
STRONG></
A> Base<
BR>
><
STRONG>Compatibility:</
STRONG></
A>> Only available in Apache 1.3.5
><
STRONG>Module:</
STRONG></
A> mod_log_config
The RefererIgnore directive adds to the list of strings to ignore in
Referer headers. If any of the strings in the list is contained in
the Referer header, then no referrer information will be logged for the
<
STRONG>Note:</
STRONG> <
EM>All</
EM> transaction logfiles
(defined by <
CODE>CustomLog</
CODE> or <
CODE>TransferLog</
CODE>) in
the same server scope as the <
CODE>RefererIgnore</
CODE> (<
EM>
e.g.</
EM>,
in the same <
CODE><VirtualHost></
CODE> container)
this directive. If you want to control this behaviour on a
<
EM>per</
EM>-logfile basis, you should use the
<
A HREF="#customlog-conditional">conditional <
SAMP>CustomLog</
SAMP></
A>
<
H2><
A NAME="transferlog">TransferLog</
A></
H2>
<!--%plaintext <?INDEX {\tt TransferLog} directive> --> ><
STRONG>Syntax:</
STRONG></
A> TransferLog <
EM>file-pipe</
EM><
BR>
><
STRONG>Default:</
STRONG></
A> none<
BR>
><
STRONG>Context:</
STRONG></
A> server config, virtual host<
BR>
><
STRONG>Status:</
STRONG></
A> Base<
BR>
><
STRONG>Module:</
STRONG></
A> mod_log_config<
P>
The TransferLog directive adds a log file in the format defined by the
><
SAMP>LogFormat</
SAMP></
A>
directive, or Common Log Format if no other default format has been
<
EM>File-pipe</
EM> is one
<
DD>A filename relative to the <
A HREF="core.html#serverroot">ServerRoot</
A>.
<
DT> `|' followed by a command
<
DD>A program to receive the agent log information on its standard input.
Note the a new program will not be started for a VirtualHost if it inherits
the TransferLog from the main server.
<
STRONG>Security:</
STRONG> if a program is used, then it will be
run under the user who started httpd. This will be root if the server
was started by root; be sure that the program is secure.<
P>