mod_log_config.xml revision 77b840c850ef60fd6a119f3a7e907412d78b77d5
c3fcea07965f59723831e23da647a77518285b8eslive<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
e942c741056732f50da2074b36fe59805d370650slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
6c822625991844de5475569ff656a69965aa6affrbowen<modulesynopsis>
c3fcea07965f59723831e23da647a77518285b8eslive<description>Logging of the requests made to the server</description>
6c822625991844de5475569ff656a69965aa6affrbowen <p>This module provides for flexible logging of client
6c822625991844de5475569ff656a69965aa6affrbowen requests. Logs are written in a customizable format, and may be
6c822625991844de5475569ff656a69965aa6affrbowen written directly to a file, or to an external program.
6c822625991844de5475569ff656a69965aa6affrbowen Conditional logging is provided so that individual requests may
6c822625991844de5475569ff656a69965aa6affrbowen be included or excluded from the logs based on characteristics
6c822625991844de5475569ff656a69965aa6affrbowen of the request.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <p>Three directives are provided by this module:
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <directive module="mod_log_config">TransferLog</directive> to create
10542e490a1b0abf5c02e022f29ea2074ca4d435nd a log file, <directive module="mod_log_config">LogFormat</directive>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd to set a custom format, and <directive module="mod_log_config"
10542e490a1b0abf5c02e022f29ea2074ca4d435nd >CustomLog</directive> to define a log file and format in one
10542e490a1b0abf5c02e022f29ea2074ca4d435nd step. The <directive>TransferLog</directive> and <directive
10542e490a1b0abf5c02e022f29ea2074ca4d435nd >CustomLog</directive> directives can be used multiple times in each
10542e490a1b0abf5c02e022f29ea2074ca4d435nd server to cause each request to be logged to multiple files.</p>
c3fcea07965f59723831e23da647a77518285b8eslive<seealso><a href="/logs.html">Apache Log Files</a></seealso>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <p>The format argument to the <directive module="mod_log_config"
10542e490a1b0abf5c02e022f29ea2074ca4d435nd >LogFormat</directive> and <directive module="mod_log_config"
10542e490a1b0abf5c02e022f29ea2074ca4d435nd >CustomLog</directive> directives is a string. This string is
6c822625991844de5475569ff656a69965aa6affrbowen logged to the log file for each request. It can contain literal
6c822625991844de5475569ff656a69965aa6affrbowen characters copied into the log files and the c-type control
6c822625991844de5475569ff656a69965aa6affrbowen characters "\n" and "\t" to represent new-lines and tabs.
6c822625991844de5475569ff656a69965aa6affrbowen Literal quotes and back-slashes should be escaped with
6c822625991844de5475569ff656a69965aa6affrbowen back-slashes.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <p>The characteristics of the request itself are logged by
10542e490a1b0abf5c02e022f29ea2074ca4d435nd placing "<code>%</code>" directives in the format string, which are
10542e490a1b0abf5c02e022f29ea2074ca4d435nd replaced in the log file by the values as follows:</p>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Bytes sent, excluding HTTP headers. In CLF format, <em>i.e.</em>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd a '<code>-</code>' rather than a 0 when no bytes are sent.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The contents of cookie <var>Foobar</var> in the request sent
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The time taken to serve the request, in microseconds.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The contents of the environment variable
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The contents of <code><var>Foobar</var>:</code> header line(s)
77b840c850ef60fd6a119f3a7e907412d78b77d5nd <td>Remote logname (from identd, if supplied). This will return a
77b840c850ef60fd6a119f3a7e907412d78b77d5nd dash unless <module>mod_ident</module> is present and <directive
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The contents of <code><var>Foobar</var>:</code> header line(s)
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The canonical port of the server serving the request</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The process ID of the child that serviced the request.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The query string (prepended with a <code>?</code> if a query
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Status. For requests that got internally redirected, this is
10542e490a1b0abf5c02e022f29ea2074ca4d435nd the status of the *original* request --- <code>%...>s</code>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Time, in common log format time format (standard english
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The time, in the form given by format, which should be in
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <code>strftime(3)</code> format. (potentially localized)</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The time taken to serve the request, in seconds.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Remote user (from auth; may be bogus if return status
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The URL path requested, not including any query string.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The canonical <directive module="core">ServerName</directive>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>The server name according to the <directive module="core"
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Connection status when response is completed:
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>connection aborted before the response completed.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>connection may be kept alive after the response is
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>connection will be closed after the response is
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <p>(This directive was <code>%...c</code> in late versions of Apache
10542e490a1b0abf5c02e022f29ea2074ca4d435nd 1.3, but this conflicted with the historical ssl
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <code>%...{<var>var</var>}c</code> syntax.)</p></td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Bytes received, including request and headers, cannot be zero.
10542e490a1b0abf5c02e022f29ea2074ca4d435nd You need to enable <module>mod_logio</module> to use this.</td></tr>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <td>Bytes sent, including headers, cannot be zero. You need to
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <p>The "<var>...</var>" can be nothing at all (<em>e.g.</em>,
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <code>"%h %u %r %s %b"</code>), or it can indicate conditions for
10542e490a1b0abf5c02e022f29ea2074ca4d435nd inclusion of the item (which will cause it to be replaced with "-" if
10542e490a1b0abf5c02e022f29ea2074ca4d435nd the condition is not met). The forms of condition are a list of
6c822625991844de5475569ff656a69965aa6affrbowen HTTP status codes, which may or may not be preceded by "!".
10542e490a1b0abf5c02e022f29ea2074ca4d435nd Thus, "%400,501{User-agent}i" logs <code>User-agent:</code> on 400
10542e490a1b0abf5c02e022f29ea2074ca4d435nd errors and 501 errors (Bad Request, Not Implemented) only;
10542e490a1b0abf5c02e022f29ea2074ca4d435nd "%!200,304,302{Referer}i" logs <code>Referer:</code> on all requests
10542e490a1b0abf5c02e022f29ea2074ca4d435nd which did <em>not</em> return some sort of normal status.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <p>Note that there is no escaping performed on the strings from
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <code>%...r</code>, <code>%...i</code> and <code>%...o</code>. This
10542e490a1b0abf5c02e022f29ea2074ca4d435nd is mainly to comply with the requirements of the Common Log Format.
10542e490a1b0abf5c02e022f29ea2074ca4d435nd This implies that clients can insert control characters into the log,
10542e490a1b0abf5c02e022f29ea2074ca4d435nd so care should be taken when dealing with raw log files.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
6c822625991844de5475569ff656a69965aa6affrbowen <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
10542e490a1b0abf5c02e022f29ea2074ca4d435nd >ServerName</directive> and <directive module="mpm_common"
10542e490a1b0abf5c02e022f29ea2074ca4d435nd >Listen</directive> of the server serving the
6c822625991844de5475569ff656a69965aa6affrbowen request are used for <code>%v</code> and <code>%p</code>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd respectively. This happens regardless of the <directive
6c822625991844de5475569ff656a69965aa6affrbowen because otherwise log analysis programs would have to duplicate
6c822625991844de5475569ff656a69965aa6affrbowen the entire vhost matching algorithm in order to decide what
6c822625991844de5475569ff656a69965aa6affrbowen host really served the request.</p>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<section id="security"><title>Security Considerations</title>
6c822625991844de5475569ff656a69965aa6affrbowen href="/misc/security_tips.html#serverroot">security tips</a>
6c822625991844de5475569ff656a69965aa6affrbowen document for details on why your security could be compromised
6c822625991844de5475569ff656a69965aa6affrbowen if the directory where logfiles are stored is writable by
6c822625991844de5475569ff656a69965aa6affrbowen anyone other than the user that starts the server.</p>
6c822625991844de5475569ff656a69965aa6affrbowen<directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<description>Sets filename for the logging of cookies</description>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<contextlist><context>server config</context><context>virtual host</context>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd</contextlist>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<compatibility>This directive is deprecated.</compatibility>
6c822625991844de5475569ff656a69965aa6affrbowen <p>The <directive>CookieLog</directive> directive sets the
6c822625991844de5475569ff656a69965aa6affrbowen filename for logging of cookies. The filename is relative to the
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <directive module="core">ServerRoot</directive>. This directive is
199a8ee5984e3708982fab1ba6ebb0a5feaea90cnd included only for compatibility with <code>mod_cookies</code>,
6c822625991844de5475569ff656a69965aa6affrbowen and is deprecated.</p>
6c822625991844de5475569ff656a69965aa6affrbowen</directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<description>Sets filename and format of log file</description>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<contextlist><context>server config</context><context>virtual host</context>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd</contextlist>
6c822625991844de5475569ff656a69965aa6affrbowen <p>The <directive>CustomLog</directive> directive is used to
6c822625991844de5475569ff656a69965aa6affrbowen log requests to the server. A log format is specified, and the
6c822625991844de5475569ff656a69965aa6affrbowen logging can optionally be made conditional on request
6c822625991844de5475569ff656a69965aa6affrbowen characteristics using environment variables.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <p>The first argument, which specifies the location to which
6c822625991844de5475569ff656a69965aa6affrbowen the logs will be written, can take on one of the following two
6c822625991844de5475569ff656a69965aa6affrbowen types of values:</p>
6c822625991844de5475569ff656a69965aa6affrbowen <dd>The pipe character "<code>|</code>", followed by the path
6c822625991844de5475569ff656a69965aa6affrbowen to a program to receive the log information on its standard
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <p>If a program is used, then it will be run under the user who
10542e490a1b0abf5c02e022f29ea2074ca4d435nd started httpd. This will be root if the server was started by root;
10542e490a1b0abf5c02e022f29ea2074ca4d435nd be sure that the program is secure.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <p>The second argument specifies what will be written to the
10542e490a1b0abf5c02e022f29ea2074ca4d435nd log file. It can specify either a <var>nickname</var> defined by
10542e490a1b0abf5c02e022f29ea2074ca4d435nd a previous <directive module="mod_log_config">LogFormat</directive>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd directive, or it can be an explicit <var>format</var> string as
10542e490a1b0abf5c02e022f29ea2074ca4d435nd described in the <a href="#formats">log formats</a> section.</p>
6c822625991844de5475569ff656a69965aa6affrbowen <p>For example, the following two sets of directives have
6c822625991844de5475569ff656a69965aa6affrbowen exactly the same effect:</p>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd # CustomLog with format nickname<br />
10542e490a1b0abf5c02e022f29ea2074ca4d435nd LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
10542e490a1b0abf5c02e022f29ea2074ca4d435nd # CustomLog with explicit format string<br />
10542e490a1b0abf5c02e022f29ea2074ca4d435nd </example>
6c822625991844de5475569ff656a69965aa6affrbowen <p>The third argument is optional and allows the decision on
6c822625991844de5475569ff656a69965aa6affrbowen whether or not to log a particular request to be based on the
6c822625991844de5475569ff656a69965aa6affrbowen presence or absence of a particular variable in the server
6c822625991844de5475569ff656a69965aa6affrbowen environment. If the specified <a href="/env.html">environment
6c822625991844de5475569ff656a69965aa6affrbowen variable</a> is set for the request (or is not set, in the case
10542e490a1b0abf5c02e022f29ea2074ca4d435nd of a '<code>env=!<var>name</var></code>' clause), then the
6c822625991844de5475569ff656a69965aa6affrbowen request will be logged.</p>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <p>Environment variables can be set on a per-request
01814afd8daa1fb017fcb956ac01d173763f896eyoshiki example, if you want to record requests for all GIF
01814afd8daa1fb017fcb956ac01d173763f896eyoshiki images on your server in a separate logfile but not in your main
6c822625991844de5475569ff656a69965aa6affrbowen log, you can use:</p>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd SetEnvIf Request_URI \.gif$ gif-image<br />
10542e490a1b0abf5c02e022f29ea2074ca4d435nd CustomLog nongif-requests.log common env=!gif-image
10542e490a1b0abf5c02e022f29ea2074ca4d435nd </example>
6c822625991844de5475569ff656a69965aa6affrbowen</directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<description>Describes a format for use in a log file</description>
7cb7b06acc8700479d4d4080b8c7bc5278f20028slive<default>LogFormat "%h %l %u %t \"%r\" %>s %b"</default>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<contextlist><context>server config</context><context>virtual host</context>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd</contextlist>
6c822625991844de5475569ff656a69965aa6affrbowen <p>This directive specifies the format of the access log
6c822625991844de5475569ff656a69965aa6affrbowen <p>The <directive>LogFormat</directive> directive can take one of two
6c822625991844de5475569ff656a69965aa6affrbowen forms. In the first form, where only one argument is specified,
6c822625991844de5475569ff656a69965aa6affrbowen this directive sets the log format which will be used by logs
6c822625991844de5475569ff656a69965aa6affrbowen specified in subsequent <directive>TransferLog</directive>
6c822625991844de5475569ff656a69965aa6affrbowen directives. The single argument can specify an explicit
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <var>format</var> as discussed in <a href="#formats">custom log
6c822625991844de5475569ff656a69965aa6affrbowen formats</a> section above. Alternatively, it can use a
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <var>nickname</var> to refer to a log format defined in a
6c822625991844de5475569ff656a69965aa6affrbowen previous <directive>LogFormat</directive> directive as described
6c822625991844de5475569ff656a69965aa6affrbowen <p>The second form of the <directive>LogFormat</directive>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd directive associates an explicit <var>format</var> with a
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <var>nickname</var>. This <var>nickname</var> can then be used in
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <directive module="mod_log_config">CustomLog</directive> directives
10542e490a1b0abf5c02e022f29ea2074ca4d435nd rather than repeating the entire format string. A
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <directive>LogFormat</directive> directive that defines a nickname
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <strong>does nothing else</strong> -- that is, it <em>only</em>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd defines the nickname, it doesn't actually apply the format and make
10542e490a1b0abf5c02e022f29ea2074ca4d435nd it the default. Therefore, it will not affect subsequent
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <directive module="mod_log_config">TransferLog</directive> directives.
10542e490a1b0abf5c02e022f29ea2074ca4d435nd In addition, <directive>LogFormat</directive> cannot use one nickname
10542e490a1b0abf5c02e022f29ea2074ca4d435nd to define another nickname. Note, that the nickname should not contain
10542e490a1b0abf5c02e022f29ea2074ca4d435nd LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
10542e490a1b0abf5c02e022f29ea2074ca4d435nd </example>
6c822625991844de5475569ff656a69965aa6affrbowen</directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen<description>Specifly location of a log file</description>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<syntax>TransferLog <var>file</var>|<var>pipe</var></syntax>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd<contextlist><context>server config</context><context>virtual host</context>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd</contextlist>
6c822625991844de5475569ff656a69965aa6affrbowen <p>This directive has exactly the same arguments and effect as
10542e490a1b0abf5c02e022f29ea2074ca4d435nd the <directive module="mod_log_config">CustomLog</directive>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd directive, with the exception that it does not allow the log format
10542e490a1b0abf5c02e022f29ea2074ca4d435nd to be specified explicitly or for conditional logging of requests.
10542e490a1b0abf5c02e022f29ea2074ca4d435nd Instead, the log format is determined by the most recently specified
10542e490a1b0abf5c02e022f29ea2074ca4d435nd <directive module="mod_log_config">LogFormat</directive> directive
10542e490a1b0abf5c02e022f29ea2074ca4d435nd (which does not define a nickname). Common Log Format is used if no
6c822625991844de5475569ff656a69965aa6affrbowen other format has been specified.</p>
10542e490a1b0abf5c02e022f29ea2074ca4d435nd LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
10542e490a1b0abf5c02e022f29ea2074ca4d435nd </example>
6c822625991844de5475569ff656a69965aa6affrbowen</directivesynopsis>
6c822625991844de5475569ff656a69965aa6affrbowen</modulesynopsis>