1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>mod_log_config - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
14 <div id="page-header">
15 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
16 <p class="apache">Apache HTTP Server Version 2.1</p>
17 <img alt="" src="../images/feather.gif" /></div>
18 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
20 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs-project/">Documentation</a> > <a href="../">Version 2.1</a> > <a href="./">Modules</a></div>
21 <div id="page-content">
22 <div id="preamble"><h1>Apache Module mod_log_config</h1>
24 <p><span>Available Languages: </span><a href="../en/mod/mod_log_config.html" title="English"> en </a> |
25 <a href="../ja/mod/mod_log_config.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
27 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Logging of the requests made to the server</td></tr>
28 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
29 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>log_config_module</td></tr>
30 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_log_config.c</td></tr></table>
33 <p>This module provides for flexible logging of client
34 requests. Logs are written in a customizable format, and may be
35 written directly to a file, or to an external program.
36 Conditional logging is provided so that individual requests may
37 be included or excluded from the logs based on characteristics
40 <p>Three directives are provided by this module:
41 <code class="directive"><a href="#transferlog">TransferLog</a></code> to create
42 a log file, <code class="directive"><a href="#logformat">LogFormat</a></code>
43 to set a custom format, and <code class="directive"><a href="#customlog">CustomLog</a></code> to define a log file and format in one
44 step. The <code class="directive">TransferLog</code> and <code class="directive">CustomLog</code> directives can be used multiple times in each
45 server to cause each request to be logged to multiple files.</p>
47 <div id="quickview"><h3 class="directives">Directives</h3>
49 <li><img alt="" src="../images/down.gif" /> <a href="#cookielog">CookieLog</a></li>
50 <li><img alt="" src="../images/down.gif" /> <a href="#customlog">CustomLog</a></li>
51 <li><img alt="" src="../images/down.gif" /> <a href="#logformat">LogFormat</a></li>
52 <li><img alt="" src="../images/down.gif" /> <a href="#transferlog">TransferLog</a></li>
56 <li><img alt="" src="../images/down.gif" /> <a href="#formats">Custom Log Formats</a></li>
57 <li><img alt="" src="../images/down.gif" /> <a href="#security">Security Considerations</a></li>
58 </ul><h3>See also</h3>
60 <li><a href="../logs.html">Apache Log Files</a></li>
62 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
64 <h2><a name="formats" id="formats">Custom Log Formats</a></h2>
66 <p>The format argument to the <code class="directive"><a href="#logformat">LogFormat</a></code> and <code class="directive"><a href="#customlog">CustomLog</a></code> directives is a string. This string is
67 used to log each request to the log file. It can contain literal
68 characters copied into the log files and the C-style control
69 characters "\n" and "\t" to represent new-lines and tabs.
70 Literal quotes and back-slashes should be escaped with
73 <p>The characteristics of the request itself are logged by
74 placing "<code>%</code>" directives in the format string, which are
75 replaced in the log file by the values as follows:</p>
77 <table class="bordered"><tr class="header"><th>Format String</th>
78 <th>Description</th></tr>
79 <tr><td><code>%%</code></td>
80 <td>The percent sign</td></tr>
81 <tr class="odd"><td><code>%...a</code></td>
82 <td>Remote IP-address</td></tr>
83 <tr><td><code>%...A</code></td>
84 <td>Local IP-address</td></tr>
85 <tr class="odd"><td><code>%...B</code></td>
86 <td>Bytes sent, excluding HTTP headers.</td></tr>
87 <tr><td><code>%...b</code></td>
88 <td>Bytes sent, excluding HTTP headers. In CLF format, <em>i.e.</em>
89 a '<code>-</code>' rather than a 0 when no bytes are sent.</td></tr>
90 <tr class="odd"><td><code>%...{<var>Foobar</var>}C</code></td>
91 <td>The contents of cookie <var>Foobar</var> in the request sent
92 to the server.</td></tr>
93 <tr><td><code>%...D</code></td>
94 <td>The time taken to serve the request, in microseconds.</td></tr>
95 <tr class="odd"><td><code>%...{<var>FOOBAR</var>}e</code></td>
96 <td>The contents of the environment variable
97 <var>FOOBAR</var></td></tr>
98 <tr><td><code>%...f</code></td>
99 <td>Filename</td></tr>
100 <tr class="odd"><td><code>%...h</code></td>
101 <td>Remote host</td></tr>
102 <tr><td><code>%...H</code></td>
103 <td>The request protocol</td></tr>
104 <tr class="odd"><td><code>%...{<var>Foobar</var>}i</code></td>
105 <td>The contents of <code><var>Foobar</var>:</code> header line(s)
106 in the request sent to the server.</td></tr>
107 <tr><td><code>%...l</code></td>
108 <td>Remote logname (from identd, if supplied). This will return a
109 dash unless <code class="module"><a href="../mod/mod_ident.html">mod_ident</a></code> is present and <code class="directive"><a href="../mod/mod_ident.html#identitycheck">IdentityCheck</a></code> is set
110 <code>On</code>.</td></tr>
111 <tr class="odd"><td><code>%...m</code></td>
112 <td>The request method</td></tr>
113 <tr><td><code>%...{<var>Foobar</var>}n</code></td>
114 <td>The contents of note <var>Foobar</var> from another
116 <tr class="odd"><td><code>%...{<var>Foobar</var>}o</code></td>
117 <td>The contents of <code><var>Foobar</var>:</code> header line(s)
118 in the reply.</td></tr>
119 <tr><td><code>%...p</code></td>
120 <td>The canonical port of the server serving the request</td></tr>
121 <tr class="odd"><td><code>%...P</code></td>
122 <td>The process ID of the child that serviced the request.</td></tr>
123 <tr><td><code>%...{<var>format</var>}P</code></td>
124 <td>The process ID or thread id of the child that serviced the
125 request. Valid formats are <code>pid</code> and <code>tid</code>.
127 <tr class="odd"><td><code>%...q</code></td>
128 <td>The query string (prepended with a <code>?</code> if a query
129 string exists, otherwise an empty string)</td></tr>
130 <tr><td><code>%...r</code></td>
131 <td>First line of request</td></tr>
132 <tr class="odd"><td><code>%...s</code></td>
133 <td>Status. For requests that got internally redirected, this is
134 the status of the *original* request --- <code>%...>s</code>
135 for the last.</td></tr>
136 <tr><td><code>%...t</code></td>
137 <td>Time, in common log format time format (standard english
139 <tr class="odd"><td><code>%...{<var>format</var>}t</code></td>
140 <td>The time, in the form given by format, which should be in
141 <code>strftime(3)</code> format. (potentially localized)</td></tr>
142 <tr><td><code>%...T</code></td>
143 <td>The time taken to serve the request, in seconds.</td></tr>
144 <tr class="odd"><td><code>%...u</code></td>
145 <td>Remote user (from auth; may be bogus if return status
146 (<code>%s</code>) is 401)</td></tr>
147 <tr><td><code>%...U</code></td>
148 <td>The URL path requested, not including any query string.</td></tr>
149 <tr class="odd"><td><code>%...v</code></td>
150 <td>The canonical <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
151 of the server serving the request.</td></tr>
152 <tr><td><code>%...V</code></td>
153 <td>The server name according to the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> setting.</td></tr>
154 <tr class="odd"><td><code>%...X</code></td>
155 <td>Connection status when response is completed:
159 <tr><td><code>X</code> =</td>
160 <td>connection aborted before the response completed.</td></tr>
161 <tr><td><code>+</code> =</td>
162 <td>connection may be kept alive after the response is
164 <tr><td><code>-</code> = </td>
165 <td>connection will be closed after the response is
169 <p>(This directive was <code>%...c</code> in late versions of Apache
170 1.3, but this conflicted with the historical ssl
171 <code>%...{<var>var</var>}c</code> syntax.)</p></td></tr>
172 <tr><td><code>%...I</code></td>
173 <td>Bytes received, including request and headers, cannot be zero.
174 You need to enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
175 <tr class="odd"><td><code>%...O</code></td>
176 <td>Bytes sent, including headers, cannot be zero. You need to
177 enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
180 <p>The "<var>...</var>" can be nothing at all (<em>e.g.</em>,
181 <code>"%h %u %r %s %b"</code>), or it can indicate conditions for
182 inclusion of the item (which will cause it to be replaced with "-" if
183 the condition is not met). The forms of condition are a list of
184 HTTP status codes, which may or may not be preceded by "!".
185 Thus, "%400,501{User-agent}i" logs <code>User-agent:</code> on 400
186 errors and 501 errors (Bad Request, Not Implemented) only;
187 "%!200,304,302{Referer}i" logs <code>Referer:</code> on all requests
188 which did <em>not</em> return some sort of normal status.</p>
190 <p>The modifiers "<" and ">" can be used for requests that
191 have been internally redirected to choose whether the original or
192 final (respectively) request should be consulted. By default, the
193 <code>%</code> directives <code>%s, %U, %T, %D,</code> and
194 <code>%r</code> look at the original request while all others look
195 at the final request. So for example, <code>%>s</code> can be
196 used to record the final status of the request and
197 <code>%<u</code> can be used to record the original
198 authenticated user on a request that is internally redirect to an
199 unauthenticated resource.</p>
201 <p>Note that in httpd 2.0 versions prior to 2.0.46, no escaping was performed
202 on the strings from <code>%...r</code>, <code>%...i</code> and
203 <code>%...o</code>. This was mainly to comply with the requirements of
204 the Common Log Format. This implied that clients could insert control
205 characters into the log, so you had to be quite careful when dealing
206 with raw log files.</p>
208 <p>For security reasons, starting with 2.0.46, non-printable and
209 other special characters are escaped mostly by using
210 <code>\x<var>hh</var></code> sequences, where <var>hh</var> stands for
211 the hexadecimal representation of the raw byte. Exceptions from this
212 rule are <code>"</code> and <code>\</code> which are escaped by prepending
213 a backslash, and all whitespace characters which are written in their
214 C-style notation (<code>\n</code>, <code>\t</code> etc).</p>
216 <p>Some commonly used log format strings are:</p>
219 <dt>Common Log Format (CLF)</dt>
220 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
222 <dt>Common Log Format with Virtual Host</dt>
223 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
225 <dt>NCSA extended/combined log format</dt>
226 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
227 \"%{User-agent}i\""</code></dd>
229 <dt>Referer log format</dt>
230 <dd><code>"%{Referer}i -> %U"</code></dd>
232 <dt>Agent (Browser) log format</dt>
233 <dd><code>"%{User-agent}i"</code></dd>
236 <p>Note that the canonical <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> and <code class="directive"><a href="../mod/mpm_common.html#listen">Listen</a></code> of the server serving the
237 request are used for <code>%v</code> and <code>%p</code>
238 respectively. This happens regardless of the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> setting
239 because otherwise log analysis programs would have to duplicate
240 the entire vhost matching algorithm in order to decide what
241 host really served the request.</p>
242 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
243 <div class="section">
244 <h2><a name="security" id="security">Security Considerations</a></h2>
245 <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
246 document for details on why your security could be compromised
247 if the directory where logfiles are stored is writable by
248 anyone other than the user that starts the server.</p>
250 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
251 <div class="directive-section"><h2><a name="CookieLog" id="CookieLog">CookieLog</a> <a name="cookielog" id="cookielog">Directive</a></h2>
252 <table class="directive">
253 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename for the logging of cookies</td></tr>
254 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CookieLog <var>filename</var></code></td></tr>
255 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
256 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
257 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
258 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>This directive is deprecated.</td></tr>
260 <p>The <code class="directive">CookieLog</code> directive sets the
261 filename for logging of cookies. The filename is relative to the
262 <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>. This directive is
263 included only for compatibility with <code>mod_cookies</code>,
264 and is deprecated.</p>
267 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
268 <div class="directive-section"><h2><a name="CustomLog" id="CustomLog">CustomLog</a> <a name="customlog" id="customlog">Directive</a></h2>
269 <table class="directive">
270 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename and format of log file</td></tr>
271 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CustomLog <var>file</var>|<var>pipe</var>
272 <var>format</var>|<var>nickname</var>
273 [env=[!]<var>environment-variable</var>]</code></td></tr>
274 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
275 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
276 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
278 <p>The <code class="directive">CustomLog</code> directive is used to
279 log requests to the server. A log format is specified, and the
280 logging can optionally be made conditional on request
281 characteristics using environment variables.</p>
283 <p>The first argument, which specifies the location to which
284 the logs will be written, can take one of the following two
288 <dt><var>file</var></dt>
289 <dd>A filename, relative to the <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>.</dd>
291 <dt><var>pipe</var></dt>
292 <dd>The pipe character "<code>|</code>", followed by the path
293 to a program to receive the log information on its standard
296 <div class="warning"><h3>Security:</h3>
297 <p>If a program is used, then it will be run as the user who
298 started httpd. This will be root if the server was started by root;
299 be sure that the program is secure.</p>
301 <div class="warning"><h3>Note</h3>
302 <p>When entering a file path on non-Unix platforms, care should be taken
303 to make sure that only forward slashed are used even though the platform
304 may allow the use of back slashes. In general it is a good idea to always
305 use forward slashes throughout the configuration files.</p>
309 <p>The second argument specifies what will be written to the
310 log file. It can specify either a <var>nickname</var> defined by
311 a previous <code class="directive"><a href="#logformat">LogFormat</a></code>
312 directive, or it can be an explicit <var>format</var> string as
313 described in the <a href="#formats">log formats</a> section.</p>
315 <p>For example, the following two sets of directives have
316 exactly the same effect:</p>
318 <div class="example"><p><code>
319 # CustomLog with format nickname<br />
320 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
321 CustomLog logs/access_log common<br />
323 # CustomLog with explicit format string<br />
324 CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"
327 <p>The third argument is optional and controls whether or
328 not to log a particular request based on the
329 presence or absence of a particular variable in the server
330 environment. If the specified <a href="../env.html">environment
331 variable</a> is set for the request (or is not set, in the case
332 of a '<code>env=!<var>name</var></code>' clause), then the
333 request will be logged.</p>
335 <p>Environment variables can be set on a per-request
336 basis using the <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
337 and/or <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> modules. For
338 example, if you want to record requests for all GIF
339 images on your server in a separate logfile but not in your main
340 log, you can use:</p>
342 <div class="example"><p><code>
343 SetEnvIf Request_URI \.gif$ gif-image<br />
344 CustomLog gif-requests.log common env=gif-image<br />
345 CustomLog nongif-requests.log common env=!gif-image
349 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
350 <div class="directive-section"><h2><a name="LogFormat" id="LogFormat">LogFormat</a> <a name="logformat" id="logformat">Directive</a></h2>
351 <table class="directive">
352 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Describes a format for use in a log file</td></tr>
353 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LogFormat <var>format</var>|<var>nickname</var>
354 [<var>nickname</var>]</code></td></tr>
355 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LogFormat "%h %l %u %t \"%r\" %>s %b"</code></td></tr>
356 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
357 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
358 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
360 <p>This directive specifies the format of the access log
363 <p>The <code class="directive">LogFormat</code> directive can take one of two
364 forms. In the first form, where only one argument is specified,
365 this directive sets the log format which will be used by logs
366 specified in subsequent <code class="directive">TransferLog</code>
367 directives. The single argument can specify an explicit
368 <var>format</var> as discussed in the <a href="#formats">custom log
369 formats</a> section above. Alternatively, it can use a
370 <var>nickname</var> to refer to a log format defined in a
371 previous <code class="directive">LogFormat</code> directive as described
374 <p>The second form of the <code class="directive">LogFormat</code>
375 directive associates an explicit <var>format</var> with a
376 <var>nickname</var>. This <var>nickname</var> can then be used in
377 subsequent <code class="directive">LogFormat</code> or
378 <code class="directive"><a href="#customlog">CustomLog</a></code> directives
379 rather than repeating the entire format string. A
380 <code class="directive">LogFormat</code> directive that defines a nickname
381 <strong>does nothing else</strong> -- that is, it <em>only</em>
382 defines the nickname, it doesn't actually apply the format and make
383 it the default. Therefore, it will not affect subsequent
384 <code class="directive"><a href="#transferlog">TransferLog</a></code> directives.
385 In addition, <code class="directive">LogFormat</code> cannot use one nickname
386 to define another nickname. Note that the nickname should not contain
387 percent signs (<code>%</code>).</p>
389 <div class="example"><h3>Example</h3><p><code>
390 LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
394 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
395 <div class="directive-section"><h2><a name="TransferLog" id="TransferLog">TransferLog</a> <a name="transferlog" id="transferlog">Directive</a></h2>
396 <table class="directive">
397 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify location of a log file</td></tr>
398 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>TransferLog <var>file</var>|<var>pipe</var></code></td></tr>
399 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
400 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
401 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
403 <p>This directive has exactly the same arguments and effect as
404 the <code class="directive"><a href="#customlog">CustomLog</a></code>
405 directive, with the exception that it does not allow the log format
406 to be specified explicitly or for conditional logging of requests.
407 Instead, the log format is determined by the most recently specified
408 <code class="directive"><a href="#logformat">LogFormat</a></code> directive
409 which does not define a nickname. Common Log Format is used if no
410 other format has been specified.</p>
412 <div class="example"><h3>Example</h3><p><code>
413 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
414 TransferLog logs/access_log
419 <div class="bottomlang">
420 <p><span>Available Languages: </span><a href="../en/mod/mod_log_config.html" title="English"> en </a> |
421 <a href="../ja/mod/mod_log_config.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
422 </div><div id="footer">
423 <p class="apache">Copyright 1999-2004 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
424 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>