0N/A<?
xml version="1.0"?>
0N/A<!-- $LastChangedRevision$ --> 0N/A Licensed to the Apache Software Foundation (ASF) under one or more 0N/A contributor license agreements. See the NOTICE file distributed with 0N/A this work for additional information regarding copyright ownership. 0N/A The ASF licenses this file to You under the Apache License, Version 2.0 0N/A (the "License"); you may not use this file except in compliance with 0N/A the License. You may obtain a copy of the License at 0N/A Unless required by applicable law or agreed to in writing, software 0N/A distributed under the License is distributed on an "AS IS" BASIS, 0N/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0N/A See the License for the specific language governing permissions and 0N/A limitations under the License. 0N/A<
name>mod_log_config</
name>
0N/A<
description>Logging of the requests made to the server</
description>
0N/A<
status>Base</
status>
0N/A<
identifier>log_config_module</
identifier>
0N/A <
p>This module provides for flexible logging of client
0N/A requests. Logs are written in a customizable format, and may be
0N/A written directly to a file, or to an external program.
0N/A Conditional logging is provided so that individual requests may
0N/A be included or excluded from the logs based on characteristics
0N/A <
p>Three directives are provided by this module:
0N/A <
directive module="mod_log_config">TransferLog</
directive> to create
0N/A a log file, <
directive module="mod_log_config">LogFormat</
directive>
0N/A to set a custom format, and <
directive module="mod_log_config" 0N/A >CustomLog</
directive> to define a log file and format in one
0N/A step. The <
directive>TransferLog</
directive> and <
directive 0N/A >CustomLog</
directive> directives can be used multiple times in each
0N/A server to cause each request to be logged to multiple files.</
p>
0N/A<
section id="formats"><
title>Custom Log Formats</
title>
0N/A <
p>The format argument to the <
directive module="mod_log_config" 0N/A >LogFormat</
directive> and <
directive module="mod_log_config" 0N/A >CustomLog</
directive> directives is a string. This string is
0N/A used to log each request to the log file. It can contain literal
0N/A characters copied into the log files and the C-style control
0N/A characters "\n" and "\t" to represent new-lines and tabs.
0N/A Literal quotes and backslashes should be escaped with
0N/A <
p>The characteristics of the request itself are logged by
0N/A placing "<
code>%</
code>" directives in the format string, which are
0N/A replaced in the log file by the values as follows:</
p>
0N/A <
table border="1" style="zebra">
0N/A <
columnspec><
column width=".2"/><
column width=".8"/></
columnspec>
0N/A <
tr><
th>Format String</
th>
0N/A <
th>Description</
th></
tr>
0N/A <
tr><
td><
code>%%</
code></
td>
0N/A <
td>The percent sign</
td></
tr>
0N/A <
tr><
td><
code>%a</
code></
td>
0N/A <
td>Remote IP-address</
td></
tr>
0N/A <
tr><
td><
code>%A</
code></
td>
0N/A <
td>Local IP-address</
td></
tr>
0N/A <
tr><
td><
code>%B</
code></
td>
0N/A <
td>Size of response in bytes, excluding HTTP headers.</
td></
tr>
0N/A <
tr><
td><
code>%b</
code></
td>
0N/A <
td>Size of response in bytes, excluding HTTP headers. In CLF format, <
em>
i.e.</
em>
0N/A a '<
code>-</
code>' rather than a 0 when no bytes are sent.</
td></
tr>
0N/A <
tr><
td><
code>%{<
var>VARNAME</
var>}C</
code></
td>
0N/A <
td>The contents of cookie <
var>VARNAME</
var> in the request sent
0N/A to the server. Only version 0 cookies are fully supported.</
td></
tr>
0N/A <
tr><
td><
code>%D</
code></
td>
0N/A <
td>The time taken to serve the request, in microseconds.</
td></
tr>
0N/A <
tr><
td><
code>%{<
var>VARNAME</
var>}e</
code></
td>
0N/A <
td>The contents of the environment variable
0N/A <
var>VARNAME</
var></
td></
tr>
0N/A <
tr><
td><
code>%f</
code></
td>
0N/A <
td>Filename</
td></
tr>
0N/A <
tr><
td><
code>%h</
code></
td>
0N/A <
td>Remote host</
td></
tr>
0N/A <
tr><
td><
code>%H</
code></
td>
0N/A <
td>The request protocol</
td></
tr>
0N/A <
tr><
td><
code>%{<
var>VARNAME</
var>}i</
code></
td>
0N/A <
td>The contents of <
code><
var>VARNAME</
var>:</
code> header line(s)
0N/A in the request sent to the server. Changes made by other
0N/A modules (
e.g. <
module>mod_headers</
module>) affect this.
0N/A <
tr><
td><
code>%k</
code></
td>
0N/A <
td>Number of keepalive requests handled on this connection. Interesting if
0N/A <
directive module="core">KeepAlive</
directive> is being used, so that,
0N/A for example, a '1' means the first keepalive request after the initial
0N/A one, '2' the second, etc...;
0N/A otherwise this is always 0 (indicating the initial request).</
td></
tr>
0N/A <
tr><
td><
code>%l</
code></
td>
0N/A <
td>Remote logname (from identd, if supplied). This will return a
0N/A dash unless <
module>mod_ident</
module> is present and <
directive 0N/A module="mod_ident">IdentityCheck</
directive> is set
0N/A <
code>On</
code>.</
td></
tr>
0N/A <
tr><
td><
code>%L</
code></
td>
0N/A <
td>The request log ID from the error log (or '-' if nothing has been
0N/A logged to the error log for this request)</
td></
tr>
0N/A <
tr><
td><
code>%m</
code></
td>
0N/A <
td>The request method</
td></
tr>
0N/A <
tr><
td><
code>%{<
var>VARNAME</
var>}n</
code></
td>
0N/A <
td>The contents of note <
var>VARNAME</
var> from another
0N/A <
tr><
td><
code>%{<
var>VARNAME</
var>}o</
code></
td>
0N/A <
td>The contents of <
code><
var>VARNAME</
var>:</
code> header line(s)
0N/A in the reply.</
td></
tr>
0N/A <
tr><
td><
code>%p</
code></
td>
0N/A <
td>The canonical port of the server serving the request</
td></
tr>
0N/A <
tr><
td><
code>%{<
var>format</
var>}p</
code></
td>
0N/A <
td>The canonical port of the server serving the request or the
0N/A server's actual port or the client's actual port. Valid formats
0N/A are <
code>canonical</
code>, <
code>local</
code>, or <
code>remote</
code>.
0N/A <
tr><
td><
code>%P</
code></
td>
0N/A <
td>The process ID of the child that serviced the request.</
td></
tr>
0N/A <
tr><
td><
code>%{<
var>format</
var>}P</
code></
td>
0N/A <
td>The process ID or thread id of the child that serviced the
0N/A request. Valid formats are <
code>pid</
code>, <
code>tid</
code>,
0N/A and <
code>hextid</
code>. <
code>hextid</
code> requires APR 1.2.0 or
0N/A <
tr><
td><
code>%q</
code></
td>
0N/A <
td>The query string (prepended with a <
code>?</
code> if a query
0N/A string exists, otherwise an empty string)</
td></
tr>
0N/A <
tr><
td><
code>%r</
code></
td>
0N/A <
td>First line of request</
td></
tr>
0N/A <
tr><
td><
code>%R</
code></
td>
0N/A <
td>The handler generating the response (if any).</
td></
tr>
0N/A <
tr><
td><
code>%s</
code></
td>
0N/A <
td>Status. For requests that got internally redirected, this is
0N/A the status of the *original* request --- <
code>%>s</
code>
0N/A for the last.</
td></
tr>
0N/A <
tr><
td><
code>%t</
code></
td>
0N/A <
td>Time the request was received (standard english
0N/A <
tr><
td><
code>%{<
var>format</
var>}t</
code></
td>
0N/A <
td>The time, in the form given by format, which should be in
0N/A an extended <
code>strftime(3)</
code> format (potentially localized).
0N/A If the format starts with <
code>begin:</
code> (default) the time is taken
0N/A at the beginning of the request processing, if it starts with
0N/A <
code>end:</
code> it is the time when the log entry gets written, so
0N/A close to the end of the request processing. In addition to the formats
0N/A supported by <
code>strftime(3)</
code>, the following format tokens are
0N/A <
tr><
td><
code>sec</
code></
td><
td>number of seconds since the Epoch</
td></
tr>
0N/A <
tr><
td><
code>msec</
code></
td><
td>number of milliseconds since the Epoch</
td></
tr>
0N/A <
tr><
td><
code>usec</
code></
td><
td>number of microseconds since the Epoch</
td></
tr>
0N/A <
tr><
td><
code>msec_frac</
code></
td><
td>millisecond fraction</
td></
tr>
0N/A <
tr><
td><
code>usec_frac</
code></
td><
td>microsecond fraction</
td></
tr>
0N/A These tokens can not be combined with each other or <
code>strftime(3)</
code>
0N/A formatting in the same format string. You can use multiple
0N/A <
code>%{<
var>format</
var>}t</
code> tokens instead.
0N/A <
tr><
td><
code>%T</
code></
td>
0N/A <
td>The time taken to serve the request, in seconds.</
td></
tr>
0N/A <
tr><
td><
code>%u</
code></
td>
0N/A <
td>Remote user (from auth; may be bogus if return status
0N/A (<
code>%s</
code>) is 401)</
td></
tr>
0N/A <
tr><
td><
code>%U</
code></
td>
0N/A <
td>The URL path requested, not including any query string.</
td></
tr>
0N/A <
tr><
td><
code>%v</
code></
td>
0N/A <
td>The canonical <
directive module="core">ServerName</
directive>
0N/A of the server serving the request.</
td></
tr>
0N/A <
tr><
td><
code>%V</
code></
td>
0N/A <
td>The server name according to the <
directive module="core" 0N/A >UseCanonicalName</
directive> setting.</
td></
tr>
0N/A <
tr><
td><
code>%X</
code></
td>
0N/A <
td>Connection status when response is completed:
0N/A <
columnspec><
column width=".2"/><
column width=".6"/></
columnspec>
0N/A <
tr><
td><
code>X</
code> =</
td>
0N/A <
td>connection aborted before the response completed.</
td></
tr>
0N/A <
tr><
td><
code>+</
code> =</
td>
0N/A <
td>connection may be kept alive after the response is
0N/A <
tr><
td><
code>-</
code> = </
td>
0N/A <
td>connection will be closed after the response is
0N/A <
tr><
td><
code>%I</
code></
td>
0N/A <
td>Bytes received, including request and headers, cannot be zero.
0N/A You need to enable <
module>mod_logio</
module> to use this.</
td></
tr>
0N/A <
tr><
td><
code>%O</
code></
td>
0N/A <
td>Bytes sent, including headers, cannot be zero. You need to
0N/A enable <
module>mod_logio</
module> to use this.</
td></
tr>
0N/A <
section id="modifiers"><
title>Modifiers</
title>
0N/A <
p>Particular items can be restricted to print only for
0N/A responses with specific HTTP status codes by placing a
0N/A comma-separated list of status codes immediately following the
0N/A "%". For example, <
code>"%400,501{User-agent}i"</
code> logs
0N/A <
code>User-agent</
code> on 400 errors and 501 errors only. For
0N/A other status codes, the literal string <
code>"-"</
code> will be
0N/A logged. The status code list may be preceded by a
0N/A "<
code>!</
code>" to indicate negation:
0N/A <
code>"%!200,304,302{Referer}i"</
code> logs <
code>Referer</
code>
0N/A on all requests that do <
em>not</
em> return one of the three
0N/A specified codes.</
p>
0N/A <
p>The modifiers "<" and ">" can be used for requests that
0N/A have been internally redirected to choose whether the original
0N/A or final (respectively) request should be consulted. By
0N/A default, the <
code>%</
code> directives <
code>%s, %U, %T,
0N/A %D,</
code> and <
code>%r</
code> look at the original request
0N/A while all others look at the final request. So for example,
0N/A <
code>%>s</
code> can be used to record the final status of
0N/A the request and <
code>%<u</
code> can be used to record the
0N/A original authenticated user on a request that is internally
0N/A redirected to an unauthenticated resource.</
p>
0N/A <
section id="format-notes"><
title>Some Notes</
title>
0N/A <
p>For security reasons, starting with version 2.0.46,
0N/A non-printable and other special characters in <
code>%r</
code>,
0N/A <
code>%i</
code> and <
code>%o</
code> are escaped using
0N/A <
code>\x<
var>hh</
var></
code> sequences, where <
var>hh</
var>
0N/A stands for the hexadecimal representation of the raw
0N/A byte. Exceptions from this rule are <
code>"</
code> and
0N/A <
code>\</
code>, which are escaped by prepending a backslash, and
0N/A all whitespace characters, which are written in their C-style
0N/A notation (<
code>\n</
code>, <
code>\t</
code>, etc). In versions
0N/A prior to 2.0.46, no escaping was performed on these strings so
0N/A you had to be quite careful when dealing with raw log files.</
p>
0N/A <
p>In httpd 2.0, unlike 1.3, the <
code>%b</
code> and
0N/A <
code>%B</
code> format strings do not represent the number of
0N/A bytes sent to the client, but simply the size in bytes of the
0N/A HTTP response (which will differ, for instance, if the
0N/A connection is aborted, or if SSL is used). The <
code>%O</
code>
0N/A format provided by <
module>mod_logio</
module> will log the
0N/A actual number of bytes sent over the network.</
p>
0N/A <
p>Note: <
module>mod_cache</
module> is implemented as a
0N/A quick-handler and not as a standard handler. Therefore, the
0N/A <
code>%R</
code> format string will not return any handler
0N/A information when content caching is involved.</
p>
0N/A <
section id="examples"><
title>Examples</
title>
0N/A <
p>Some commonly used log format strings are:</
p>
0N/A <
dt>Common Log Format (CLF)</
dt>
0N/A <
dd><
code>"%h %l %u %t \"%r\" %>s %b"</
code></
dd>
0N/A <
dt>Common Log Format with Virtual Host</
dt>
0N/A <
dd><
code>"%v %h %l %u %t \"%r\" %>s %b"</
code></
dd>
0N/A <
dd><
code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
0N/A \"%{User-agent}i\""</
code></
dd>
0N/A <
dt>Referer log format</
dt>
0N/A <
dd><
code>"%{Referer}i -> %U"</
code></
dd>
0N/A <
dt>Agent (Browser) log format</
dt>
0N/A <
dd><
code>"%{User-agent}i"</
code></
dd>
0N/A <
p>You can use the <
code>%{format}t</
code> directive multiple
0N/A times to build up a time format using the extended format tokens
0N/A like <
code>msec_frac</
code>:</
p>
0N/A<
dt>Timestamp including milliseconds</
dt>
0N/A<
dd><
code>"%{%d/%b/%Y %T}t.%{msec_frac}t %{%z}t"</
code></
dd>
0N/A<
section id="security"><
title>Security Considerations</
title>
0N/A document for details on why your security could be compromised
0N/A if the directory where logfiles are stored is writable by
0N/A anyone other than the user that starts the server.</
p>
0N/A<
name>BufferedLogs</
name>
0N/A<
description>Buffer log entries in memory before writing to disk</
description>
0N/A<
syntax>BufferedLogs On|Off</
syntax>
0N/A<
default>BufferedLogs Off</
default>
0N/A<
contextlist><
context>server config</
context></
contextlist>
0N/A<
compatibility>Available in versions 2.0.41 and later.</
compatibility>
0N/A <
p>The <
directive>BufferedLogs</
directive> directive causes
0N/A <
module>mod_log_config</
module> to store several log entries in
0N/A memory and write them together to disk, rather than writing them
0N/A after each request. On some systems, this may result in more
0N/A efficient disk access and hence higher performance. It may be
0N/A set only once for the entire server; it cannot be configured
0N/A per virtual-host.</
p>
0N/A <
note>This directive should be used with caution as a crash might
0N/A cause loss of logging data.</
note>
0N/A<
name>CookieLog</
name>
0N/A<
description>Sets filename for the logging of cookies</
description>
0N/A<
syntax>CookieLog <
var>filename</
var></
syntax>
0N/A<
contextlist><
context>server config</
context><
context>virtual host</
context>
0N/A<
compatibility>This directive is deprecated.</
compatibility>
0N/A <
p>The <
directive>CookieLog</
directive> directive sets the
0N/A filename for logging of cookies. The filename is relative to the
0N/A <
directive module="core">ServerRoot</
directive>. This directive is
0N/A included only for compatibility with <
code>mod_cookies</
code>,
0N/A and is deprecated.</
p>
0N/A<
name>CustomLog</
name>
0N/A<
description>Sets filename and format of log file</
description>
0N/A<
syntax>CustomLog <
var>file</
var>|<
var>pipe</
var>
0N/A<
var>format</
var>|<
var>nickname</
var>
0N/A[env=[!]<
var>environment-variable</
var>]</
syntax>
0N/A<
contextlist><
context>server config</
context><
context>virtual host</
context>
0N/A <
p>The <
directive>CustomLog</
directive> directive is used to
0N/A log requests to the server. A log format is specified, and the
0N/A logging can optionally be made conditional on request
0N/A characteristics using environment variables.</
p>
0N/A <
p>The first argument, which specifies the location to which
0N/A the logs will be written, can take one of the following two
0N/A types of values:</
p>
0N/A <
dt><
var>file</
var></
dt>
0N/A <
dd>A filename, relative to the <
directive module="core" 0N/A >ServerRoot</
directive>.</
dd>
0N/A <
dt><
var>pipe</
var></
dt>
0N/A <
dd>The pipe character "<
code>|</
code>", followed by the path
0N/A to a program to receive the log information on its standard
0N/A input. See the notes on <
a href="/logs.html#piped">piped logs</
a>
0N/A for more information.
0N/A <
note type="warning"><
title>Security:</
title>
0N/A <
p>If a program is used, then it will be run as the user who
0N/A started <
program>httpd</
program>. This will be root if the server was
0N/A started by root; be sure that the program is secure.</
p>
0N/A <
note type="warning"><
title>Note</
title>
0N/A <
p>When entering a file path on non-Unix platforms, care should be taken
0N/A to make sure that only forward slashed are used even though the platform
0N/A may allow the use of back slashes. In general it is a good idea to always
0N/A use forward slashes throughout the configuration files.</
p>
0N/A <
p>The second argument specifies what will be written to the
0N/A log file. It can specify either a <
var>nickname</
var> defined by
0N/A a previous <
directive module="mod_log_config">LogFormat</
directive>
0N/A directive, or it can be an explicit <
var>format</
var> string as
0N/A described in the <
a href="#formats">log formats</
a> section.</
p>
0N/A <
p>For example, the following two sets of directives have
0N/A exactly the same effect:</
p>
0N/A # CustomLog with format nickname<
br />
0N/A LogFormat "%h %l %u %t \"%r\" %>s %b" common<
br />
0N/A # CustomLog with explicit format string<
br />
0N/A <
p>The third argument is optional and controls whether or
0N/A not to log a particular request based on the
0N/A presence or absence of a particular variable in the server
0N/A environment. If the specified <
a href="/env.html">environment
0N/A variable</
a> is set for the request (or is not set, in the case
0N/A of a '<
code>env=!<
var>name</
var></
code>' clause), then the
0N/A request will be logged.</
p>
0N/A <
p>Environment variables can be set on a per-request
0N/A basis using the <
module>mod_setenvif</
module>
0N/A and/
or <
module>mod_rewrite</
module> modules. For
0N/A example, if you want to record requests for all GIF
0N/A images on your server in a separate logfile but not in your main
0N/A log, you can use:</
p>
0N/A SetEnvIf Request_URI \.gif$ gif-image<
br />
0N/A <
p>Or, to reproduce the behavior of the old RefererIgnore
0N/A directive, you might use the following:</
p>
SetEnvIf Referer example\.com localreferer<
br />
<
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>
<
p>This directive specifies the format of the access log
<
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 the <
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
<
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\" %>s %b" vhost_common
<
description>Specify location of a log file</
description>
<
syntax>TransferLog <
var>file</
var>|<
var>pipe</
var></
syntax>
<
contextlist><
context>server config</
context><
context>virtual host</
context>
<
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\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<
br />