mod_log_config.xml revision 77b840c850ef60fd6a119f3a7e907412d78b77d5
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<?xml version="1.0"?>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<modulesynopsis>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<name>mod_log_config</name>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<description>Logging of the requests made to the server</description>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<status>Base</status>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<sourcefile>mod_log_config.c</sourcefile>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<identifier>log_config_module</identifier>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<summary>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <p>This module provides for flexible logging of client
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd requests. Logs are written in a customizable format, and may be
27e52281f1522522b170cafc76b08b58aa70ccaand written directly to a file, or to an external program.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd Conditional logging is provided so that individual requests may
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd be included or excluded from the logs based on characteristics
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd of the request.</p>
4b5981e276e93df97c34e4da05ca5cf8bbd937dand
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <p>Three directives are provided by this module:
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <directive module="mod_log_config">TransferLog</directive> to create
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd a log file, <directive module="mod_log_config">LogFormat</directive>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd to set a custom format, and <directive module="mod_log_config"
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd >CustomLog</directive> to define a log file and format in one
a8703cfb67133446eef7af1043640e71486e9ecand step. The <directive>TransferLog</directive> and <directive
a8703cfb67133446eef7af1043640e71486e9ecand >CustomLog</directive> directives can be used multiple times in each
a8703cfb67133446eef7af1043640e71486e9ecand server to cause each request to be logged to multiple files.</p>
a8703cfb67133446eef7af1043640e71486e9ecand</summary>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<seealso><a href="/logs.html">Apache Log Files</a></seealso>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd<section id="formats"><title>Custom Log Formats</title>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <p>The format argument to the <directive module="mod_log_config"
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd >LogFormat</directive> and <directive module="mod_log_config"
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd >CustomLog</directive> directives is a string. This string is
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd logged to the log file for each request. It can contain literal
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd characters copied into the log files and the c-type control
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd characters "\n" and "\t" to represent new-lines and tabs.
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd Literal quotes and back-slashes should be escaped with
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd back-slashes.</p>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <p>The characteristics of the request itself are logged by
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd placing "<code>%</code>" directives in the format string, which are
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd replaced in the log file by the values as follows:</p>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <table border="1" style="zebra">
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><th>Format&nbsp;String</th>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <th>Description</th></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%%</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The percent sign</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...a</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Remote IP-address</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...A</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Local IP-address</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...B</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Bytes sent, excluding HTTP headers.</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...b</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Bytes sent, excluding HTTP headers. In CLF format, <em>i.e.</em>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd a '<code>-</code>' rather than a 0 when no bytes are sent.</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...{<var>Foobar</var>}C</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The contents of cookie <var>Foobar</var> in the request sent
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd to the server.</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...D</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The time taken to serve the request, in microseconds.</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...{<var>FOOBAR</var>}e</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The contents of the environment variable
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <var>FOOBAR</var></td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...f</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Filename</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...h</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Remote host</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...H</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The request protocol</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...{<var>Foobar</var>}i</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The contents of <code><var>Foobar</var>:</code> header line(s)
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd in the request sent to the server.</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...l</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>Remote logname (from identd, if supplied). This will return a
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd dash unless <module>mod_ident</module> is present and <directive
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd module="mod_ident">IdentityCheck</directive> is set
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <code>On</code>.</td></tr>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...m</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The request method</td></tr>
ffb88a4885747797937e30a5ac8b1606da3cb4adnd
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <tr><td><code>%...{<var>Foobar</var>}n</code></td>
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd <td>The contents of note <var>Foobar</var> from another
module.</td></tr>
<tr><td><code>%...{<var>Foobar</var>}o</code></td>
<td>The contents of <code><var>Foobar</var>:</code> header line(s)
in the reply.</td></tr>
<tr><td><code>%...p</code></td>
<td>The canonical port of the server serving the request</td></tr>
<tr><td><code>%...P</code></td>
<td>The process ID of the child that serviced the request.</td></tr>
<tr><td><code>%...q</code></td>
<td>The query string (prepended with a <code>?</code> if a query
string exists, otherwise an empty string)</td></tr>
<tr><td><code>%...r</code></td>
<td>First line of request</td></tr>
<tr><td><code>%...s</code></td>
<td>Status. For requests that got internally redirected, this is
the status of the *original* request --- <code>%...&gt;s</code>
for the last.</td></tr>
<tr><td><code>%...t</code></td>
<td>Time, in common log format time format (standard english
format)</td></tr>
<tr><td><code>%...{<var>format</var>}t</code></td>
<td>The time, in the form given by format, which should be in
<code>strftime(3)</code> format. (potentially localized)</td></tr>
<tr><td><code>%...T</code></td>
<td>The time taken to serve the request, in seconds.</td></tr>
<tr><td><code>%...u</code></td>
<td>Remote user (from auth; may be bogus if return status
(<code>%s</code>) is 401)</td></tr>
<tr><td><code>%...U</code></td>
<td>The URL path requested, not including any query string.</td></tr>
<tr><td><code>%...v</code></td>
<td>The canonical <directive module="core">ServerName</directive>
of the server serving the request.</td></tr>
<tr><td><code>%...V</code></td>
<td>The server name according to the <directive module="core"
>UseCanonicalName</directive> setting.</td></tr>
<tr><td><code>%...X</code></td>
<td>Connection status when response is completed:
<table>
<tr><td><code>X</code> =</td>
<td>connection aborted before the response completed.</td></tr>
<tr><td><code>+</code> =</td>
<td>connection may be kept alive after the response is
sent.</td></tr>
<tr><td><code>-</code> = </td>
<td>connection will be closed after the response is
sent.</td></tr>
</table>
<p>(This directive was <code>%...c</code> in late versions of Apache
1.3, but this conflicted with the historical ssl
<code>%...{<var>var</var>}c</code> syntax.)</p></td></tr>
<tr><td><code>%...I</code></td>
<td>Bytes received, including request and headers, cannot be zero.
You need to enable <module>mod_logio</module> to use this.</td></tr>
<tr><td><code>%...O</code></td>
<td>Bytes sent, including headers, cannot be zero. You need to
enable <module>mod_logio</module> to use this.</td></tr>
</table>
<p>The "<var>...</var>" 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). 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 <code>User-agent:</code> on 400
errors and 501 errors (Bad Request, Not Implemented) only;
"%!200,304,302{Referer}i" logs <code>Referer:</code> on all requests
which did <em>not</em> return some sort of normal status.</p>
<p>Note that there is no escaping performed on the strings from
<code>%...r</code>, <code>%...i</code> and <code>%...o</code>. This
is mainly to comply with the requirements of the Common Log Format.
This implies that clients can insert control characters into the log,
so care should be taken when dealing with raw log files.</p>
<p>Some commonly used log format strings are:</p>
<dl>
<dt>Common Log Format (CLF)</dt>
<dd><code>"%h %l %u %t \"%r\" %&gt;s %b"</code></dd>
<dt>Common Log Format with Virtual Host</dt>
<dd><code>"%v %h %l %u %t \"%r\" %&gt;s %b"</code></dd>
<dt>NCSA extended/combined log format</dt>
<dd><code>"%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\"
\"%{User-agent}i\""</code></dd>
<dt>Referer log format</dt>
<dd><code>"%{Referer}i -&gt; %U"</code></dd>
<dt>Agent (Browser) log format</dt>
<dd><code>"%{User-agent}i"</code></dd>
</dl>
<p>Note that the canonical <directive module="core"
>ServerName</directive> and <directive module="mpm_common"
>Listen</directive> of the server serving the
request are used for <code>%v</code> and <code>%p</code>
respectively. This happens regardless of the <directive
module="core">UseCanonicalName</directive> setting
because otherwise log analysis programs would have to duplicate
the entire vhost matching algorithm in order to decide what
host really served the request.</p>
</section>
<section id="security"><title>Security Considerations</title>
<p>See the <a
href="/misc/security_tips.html#serverroot">security tips</a>
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.</p>
</section>
<directivesynopsis>
<name>CookieLog</name>
<description>Sets filename for the logging of cookies</description>
<syntax>CookieLog <var>filename</var></syntax>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<compatibility>This directive is deprecated.</compatibility>
<usage>
<p>The <directive>CookieLog</directive> directive sets the
filename for logging of cookies. The filename is relative to the
<directive module="core">ServerRoot</directive>. This directive is
included only for compatibility with <code>mod_cookies</code>,
and is deprecated.</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>CustomLog</name>
<description>Sets filename and format of log file</description>
<syntax>CustomLog <var>file</var>|<var>pipe</var>
<var>format</var>|<var>nickname</var>
[env=[!]<var>environment-variable</var>]</syntax>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<usage>
<p>The <directive>CustomLog</directive> directive is used to
log requests to the server. A log format is specified, and the
logging can optionally be made conditional on request
characteristics using environment variables.</p>
<p>The first argument, which specifies the location to which
the logs will be written, can take on one of the following two
types of values:</p>
<dl>
<dt><var>file</var></dt>
<dd>A filename, relative to the <directive module="core"
>ServerRoot</directive>.</dd>
<dt><var>pipe</var></dt>
<dd>The pipe character "<code>|</code>", followed by the path
to a program to receive the log information on its standard
input.
<note type="warning"><title>Security:</title>
<p>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>
</note></dd>
</dl>
<p>The second argument specifies what will be written to the
log file. It can specify either a <var>nickname</var> defined by
a previous <directive module="mod_log_config">LogFormat</directive>
directive, or it can be an explicit <var>format</var> string as
described in the <a href="#formats">log formats</a> section.</p>
<p>For example, the following two sets of directives have
exactly the same effect:</p>
<example>
# CustomLog with format nickname<br />
LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common<br />
CustomLog logs/access_log common<br />
<br />
# CustomLog with explicit format string<br />
CustomLog logs/access_log "%h %l %u %t \"%r\" %&gt;s %b"
</example>
<p>The third argument is optional and allows the decision on
whether or not to log a particular request to be based on the
presence or absence of a particular variable in the server
environment. If the specified <a href="/env.html">environment
variable</a> is set for the request (or is not set, in the case
of a '<code>env=!<var>name</var></code>' clause), then the
request will be logged.</p>
<p>Environment variables can be set on a per-request
basis using the <module>mod_setenvif</module>
and/or <module>mod_rewrite</module> modules. For
example, if you want to record requests for all GIF
images on your server in a separate logfile but not in your main
log, you can use:</p>
<example>
SetEnvIf Request_URI \.gif$ gif-image<br />
CustomLog gif-requests.log common env=gif-image<br />
CustomLog nongif-requests.log common env=!gif-image
</example>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>LogFormat</name>
<description>Describes a format for use in a log file</description>
<syntax>LogFormat <var>format</var>|<var>nickname</var>
[<var>nickname</var>]</syntax>
<default>LogFormat "%h %l %u %t \"%r\" %>s %b"</default>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<usage>
<p>This directive specifies the format of the access log
file.</p>
<p>The <directive>LogFormat</directive> directive can take one of two
forms. In the first form, where only one argument is specified,
this directive sets the log format which will be used by logs
specified in subsequent <directive>TransferLog</directive>
directives. The single argument can specify an explicit
<var>format</var> as discussed in <a href="#formats">custom log
formats</a> section above. Alternatively, it can use a
<var>nickname</var> to refer to a log format defined in a
previous <directive>LogFormat</directive> directive as described
below.</p>
<p>The second form of the <directive>LogFormat</directive>
directive associates an explicit <var>format</var> with a
<var>nickname</var>. This <var>nickname</var> can then be used in
subsequent <directive>LogFormat</directive> or
<directive module="mod_log_config">CustomLog</directive> directives
rather than repeating the entire format string. A
<directive>LogFormat</directive> directive that 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. Therefore, it will not affect subsequent
<directive module="mod_log_config">TransferLog</directive> directives.
In addition, <directive>LogFormat</directive> cannot use one nickname
to define another nickname. Note, that the nickname should not contain
percent signs (<code>%</code>).</p>
<example><title>Example</title>
LogFormat "%v %h %l %u %t \"%r\" %&gt;s %b" vhost_common
</example>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>TransferLog</name>
<description>Specifly location of a log file</description>
<syntax>TransferLog <var>file</var>|<var>pipe</var></syntax>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<usage>
<p>This directive has exactly the same arguments and effect as
the <directive module="mod_log_config">CustomLog</directive>
directive, with the exception that it does not allow the log format
to be specified explicitly or for conditional logging of requests.
Instead, the log format is determined by the most recently specified
<directive module="mod_log_config">LogFormat</directive> directive
(which does not define a nickname). Common Log Format is used if no
other format has been specified.</p>
<example><title>Example</title>
LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
TransferLog logs/access_log
</example>
</usage>
</directivesynopsis>
</modulesynopsis>