]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_log_config.xml
`build check-ja` :-)
[apache] / docs / manual / mod / mod_log_config.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4
5 <!--
6  Copyright 2002-2004 The Apache Software Foundation
7
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11
12      http://www.apache.org/licenses/LICENSE-2.0
13
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 -->
20
21 <modulesynopsis metafile="mod_log_config.xml.meta">
22
23 <name>mod_log_config</name>
24 <description>Logging of the requests made to the server</description>
25 <status>Base</status>
26 <sourcefile>mod_log_config.c</sourcefile>
27 <identifier>log_config_module</identifier>
28
29 <summary>
30     <p>This module provides for flexible logging of client
31     requests. Logs are written in a customizable format, and may be
32     written directly to a file, or to an external program.
33     Conditional logging is provided so that individual requests may
34     be included or excluded from the logs based on characteristics
35     of the request.</p>
36
37     <p>Three directives are provided by this module:
38     <directive module="mod_log_config">TransferLog</directive> to create
39     a log file, <directive module="mod_log_config">LogFormat</directive>
40     to set a custom format, and <directive module="mod_log_config"
41     >CustomLog</directive> to define a log file and format in one
42     step. The <directive>TransferLog</directive> and <directive
43     >CustomLog</directive> directives can be used multiple times in each
44     server to cause each request to be logged to multiple files.</p>
45 </summary>
46 <seealso><a href="../logs.html">Apache Log Files</a></seealso>
47
48 <section id="formats"><title>Custom Log Formats</title>
49
50     <p>The format argument to the <directive module="mod_log_config"
51     >LogFormat</directive> and <directive module="mod_log_config"
52     >CustomLog</directive> directives is a string. This string is
53     used to log each request to the log file. It can contain literal
54     characters copied into the log files and the C-style control
55     characters "\n" and "\t" to represent new-lines and tabs.
56     Literal quotes and back-slashes should be escaped with
57     back-slashes.</p>
58
59     <p>The characteristics of the request itself are logged by
60     placing "<code>%</code>" directives in the format string, which are
61     replaced in the log file by the values as follows:</p>
62
63     <table border="1" style="zebra">
64     <columnspec><column width=".2"/><column width=".8"/></columnspec>
65     <tr><th>Format&nbsp;String</th>
66         <th>Description</th></tr>
67
68     <tr><td><code>%%</code></td>
69         <td>The percent sign</td></tr>
70
71     <tr><td><code>%...a</code></td>
72         <td>Remote IP-address</td></tr>
73
74     <tr><td><code>%...A</code></td>
75         <td>Local IP-address</td></tr>
76
77     <tr><td><code>%...B</code></td>
78         <td>Bytes sent, excluding HTTP headers.</td></tr>
79
80     <tr><td><code>%...b</code></td>
81         <td>Bytes sent, excluding HTTP headers. In CLF format, <em>i.e.</em>
82         a '<code>-</code>' rather than a 0 when no bytes are sent.</td></tr>
83
84     <tr><td><code>%...{<var>Foobar</var>}C</code></td>
85         <td>The contents of cookie <var>Foobar</var> in the request sent
86         to the server.</td></tr>
87
88     <tr><td><code>%...D</code></td>
89         <td>The time taken to serve the request, in microseconds.</td></tr>
90
91     <tr><td><code>%...{<var>FOOBAR</var>}e</code></td>
92         <td>The contents of the environment variable
93         <var>FOOBAR</var></td></tr>
94
95     <tr><td><code>%...f</code></td>
96         <td>Filename</td></tr>
97
98     <tr><td><code>%...h</code></td>
99         <td>Remote host</td></tr>
100
101     <tr><td><code>%...H</code></td>
102         <td>The request protocol</td></tr>
103
104     <tr><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
108     <tr><td><code>%...l</code></td>
109         <td>Remote logname (from identd, if supplied). This will return a
110         dash unless <module>mod_ident</module> is present and <directive
111         module="mod_ident">IdentityCheck</directive> is set
112         <code>On</code>.</td></tr>
113
114     <tr><td><code>%...m</code></td>
115         <td>The request method</td></tr>
116
117     <tr><td><code>%...{<var>Foobar</var>}n</code></td>
118         <td>The contents of note <var>Foobar</var> from another
119         module.</td></tr>
120
121     <tr><td><code>%...{<var>Foobar</var>}o</code></td>
122         <td>The contents of <code><var>Foobar</var>:</code> header line(s)
123         in the reply.</td></tr>
124
125     <tr><td><code>%...p</code></td>
126         <td>The canonical port of the server serving the request</td></tr>
127
128     <tr><td><code>%...P</code></td>
129         <td>The process ID of the child that serviced the request.</td></tr>
130
131     <tr><td><code>%...{<var>format</var>}P</code></td>
132         <td>The process ID or thread id of the child that serviced the 
133         request.  Valid formats are <code>pid</code> and <code>tid</code>.
134         </td></tr>
135
136     <tr><td><code>%...q</code></td>
137         <td>The query string (prepended with a <code>?</code> if a query
138         string exists, otherwise an empty string)</td></tr>
139
140     <tr><td><code>%...r</code></td>
141         <td>First line of request</td></tr>
142
143     <tr><td><code>%...s</code></td>
144         <td>Status. For requests that got internally redirected, this is
145         the status of the *original* request --- <code>%...&gt;s</code>
146         for the last.</td></tr>
147
148     <tr><td><code>%...t</code></td>
149         <td>Time, in common log format time format (standard english
150         format)</td></tr>
151
152     <tr><td><code>%...{<var>format</var>}t</code></td>
153         <td>The time, in the form given by format, which should be in
154         <code>strftime(3)</code> format. (potentially localized)</td></tr>
155
156     <tr><td><code>%...T</code></td>
157         <td>The time taken to serve the request, in seconds.</td></tr>
158
159     <tr><td><code>%...u</code></td>
160         <td>Remote user (from auth; may be bogus if return status
161         (<code>%s</code>) is 401)</td></tr>
162
163     <tr><td><code>%...U</code></td>
164         <td>The URL path requested, not including any query string.</td></tr>
165
166     <tr><td><code>%...v</code></td>
167         <td>The canonical <directive module="core">ServerName</directive>
168         of the server serving the request.</td></tr>
169
170     <tr><td><code>%...V</code></td>
171         <td>The server name according to the <directive module="core"
172         >UseCanonicalName</directive> setting.</td></tr>
173
174     <tr><td><code>%...X</code></td>
175         <td>Connection status when response is completed:
176
177         <table>
178         <columnspec><column width=".2"/><column width=".6"/></columnspec>
179         <tr><td><code>X</code> =</td>
180             <td>connection aborted before the response completed.</td></tr>
181         <tr><td><code>+</code> =</td>
182             <td>connection may be kept alive after the response is
183             sent.</td></tr>
184         <tr><td><code>-</code> = </td>
185             <td>connection will be closed after the response is
186             sent.</td></tr>
187         </table>
188
189         <p>(This directive was <code>%...c</code> in late versions of Apache
190         1.3, but this conflicted with the historical ssl
191         <code>%...{<var>var</var>}c</code> syntax.)</p></td></tr>
192
193     <tr><td><code>%...I</code></td>
194         <td>Bytes received, including request and headers, cannot be zero.
195         You need to enable <module>mod_logio</module> to use this.</td></tr>
196
197     <tr><td><code>%...O</code></td>
198         <td>Bytes sent, including headers, cannot be zero. You need to
199         enable <module>mod_logio</module> to use this.</td></tr>
200     </table>
201
202     <p>The "<var>...</var>" can be nothing at all (<em>e.g.</em>,
203     <code>"%h %u %r %s %b"</code>), or it can indicate conditions for
204     inclusion of the item (which will cause it to be replaced with "-" if
205     the condition is not met). The forms of condition are a list of
206     HTTP status codes, which may or may not be preceded by "!".
207     Thus, "%400,501{User-agent}i" logs <code>User-agent:</code> on 400
208     errors and 501 errors (Bad Request, Not Implemented) only;
209     "%!200,304,302{Referer}i" logs <code>Referer:</code> on all requests
210     which did <em>not</em> return some sort of normal status.</p>
211
212     <p>Note that in httpd 2.0 versions prior to 2.0.46, no escaping was performed
213     on the strings from <code>%...r</code>, <code>%...i</code> and
214     <code>%...o</code>. This was mainly to comply with the requirements of
215     the Common Log Format. This implied that clients could insert control
216     characters into the log, so you had to be quite careful when dealing
217     with raw log files.</p>
218
219     <p>For security reasons, starting with 2.0.46, non-printable and
220     other special characters are escaped mostly by using
221     <code>\x<var>hh</var></code> sequences, where <var>hh</var> stands for
222     the hexadecimal representation of the raw byte. Exceptions from this
223     rule are <code>"</code> and <code>\</code> which are escaped by prepending
224     a backslash, and all whitespace characters which are written in their
225     C-style notation (<code>\n</code>, <code>\t</code> etc).</p>
226
227     <p>Some commonly used log format strings are:</p>
228
229     <dl>
230       <dt>Common Log Format (CLF)</dt>
231       <dd><code>"%h %l %u %t \"%r\" %&gt;s %b"</code></dd>
232
233       <dt>Common Log Format with Virtual Host</dt>
234       <dd><code>"%v %h %l %u %t \"%r\" %&gt;s %b"</code></dd>
235
236       <dt>NCSA extended/combined log format</dt>
237       <dd><code>"%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\"
238       \"%{User-agent}i\""</code></dd>
239
240       <dt>Referer log format</dt>
241       <dd><code>"%{Referer}i -&gt; %U"</code></dd>
242
243       <dt>Agent (Browser) log format</dt>
244       <dd><code>"%{User-agent}i"</code></dd>
245     </dl>
246
247     <p>Note that the canonical <directive module="core"
248     >ServerName</directive> and <directive module="mpm_common"
249     >Listen</directive> of the server serving the
250     request are used for <code>%v</code> and <code>%p</code>
251     respectively. This happens regardless of the <directive
252     module="core">UseCanonicalName</directive> setting
253     because otherwise log analysis programs would have to duplicate
254     the entire vhost matching algorithm in order to decide what
255     host really served the request.</p>
256 </section>
257
258 <section id="security"><title>Security Considerations</title>
259     <p>See the <a
260     href="../misc/security_tips.html#serverroot">security tips</a>
261     document for details on why your security could be compromised
262     if the directory where logfiles are stored is writable by
263     anyone other than the user that starts the server.</p>
264 </section>
265
266 <directivesynopsis>
267 <name>CookieLog</name>
268 <description>Sets filename for the logging of cookies</description>
269 <syntax>CookieLog <var>filename</var></syntax>
270 <contextlist><context>server config</context><context>virtual host</context>
271 </contextlist>
272 <compatibility>This directive is deprecated.</compatibility>
273
274 <usage>
275     <p>The <directive>CookieLog</directive> directive sets the 
276     filename for logging of cookies. The filename is relative to the
277     <directive module="core">ServerRoot</directive>. This directive is
278     included only for compatibility with <code>mod_cookies</code>,
279     and is deprecated.</p>
280 </usage>
281 </directivesynopsis>
282
283 <directivesynopsis>
284 <name>CustomLog</name>
285 <description>Sets filename and format of log file</description>
286 <syntax>CustomLog  <var>file</var>|<var>pipe</var>
287 <var>format</var>|<var>nickname</var>
288 [env=[!]<var>environment-variable</var>]</syntax>
289 <contextlist><context>server config</context><context>virtual host</context>
290 </contextlist>
291
292 <usage>
293     <p>The <directive>CustomLog</directive> directive is used to
294     log requests to the server. A log format is specified, and the
295     logging can optionally be made conditional on request
296     characteristics using environment variables.</p>
297
298     <p>The first argument, which specifies the location to which
299     the logs will be written, can take one of the following two
300     types of values:</p>
301
302     <dl>
303       <dt><var>file</var></dt>
304       <dd>A filename, relative to the <directive module="core"
305       >ServerRoot</directive>.</dd>
306
307       <dt><var>pipe</var></dt>
308       <dd>The pipe character "<code>|</code>", followed by the path
309       to a program to receive the log information on its standard
310       input.
311
312       <note type="warning"><title>Security:</title>
313       <p>If a program is used, then it will be run as the user who
314       started httpd. This will be root if the server was started by root;
315       be sure that the program is secure.</p>
316       </note>
317       <note type="warning"><title>Note</title>
318         <p>When entering a file path on non-Unix platforms, care should be taken
319         to make sure that only forward slashed are used even though the platform
320         may allow the use of back slashes. In general it is a good idea to always 
321         use forward slashes throughout the configuration files.</p>
322       </note></dd>
323     </dl>
324
325     <p>The second argument specifies what will be written to the
326     log file. It can specify either a <var>nickname</var> defined by
327     a previous <directive module="mod_log_config">LogFormat</directive>
328     directive, or it can be an explicit <var>format</var> string as
329     described in the <a href="#formats">log formats</a> section.</p>
330
331     <p>For example, the following two sets of directives have
332     exactly the same effect:</p>
333
334     <example>
335       # CustomLog with format nickname<br />
336       LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common<br />
337       CustomLog logs/access_log common<br />
338       <br />
339       # CustomLog with explicit format string<br />
340       CustomLog logs/access_log "%h %l %u %t \"%r\" %&gt;s %b"
341     </example>
342
343     <p>The third argument is optional and controls whether or
344     not to log a particular request based on the
345     presence or absence of a particular variable in the server
346     environment. If the specified <a href="../env.html">environment
347     variable</a> is set for the request (or is not set, in the case
348     of a '<code>env=!<var>name</var></code>' clause), then the
349     request will be logged.</p>
350
351     <p>Environment variables can be set on a per-request
352     basis using the <module>mod_setenvif</module>
353     and/or <module>mod_rewrite</module> modules. For
354     example, if you want to record requests for all GIF
355     images on your server in a separate logfile but not in your main
356     log, you can use:</p>
357     
358     <example>
359       SetEnvIf Request_URI \.gif$ gif-image<br />
360       CustomLog gif-requests.log common env=gif-image<br />
361       CustomLog nongif-requests.log common env=!gif-image
362     </example>
363 </usage>
364 </directivesynopsis>
365
366 <directivesynopsis>
367 <name>LogFormat</name>
368 <description>Describes a format for use in a log file</description>
369 <syntax>LogFormat <var>format</var>|<var>nickname</var>
370 [<var>nickname</var>]</syntax>
371 <default>LogFormat "%h %l %u %t \"%r\" %>s %b"</default>
372 <contextlist><context>server config</context><context>virtual host</context>
373 </contextlist>
374
375 <usage>
376     <p>This directive specifies the format of the access log
377     file.</p>
378
379     <p>The <directive>LogFormat</directive> directive can take one of two
380     forms. In the first form, where only one argument is specified,
381     this directive sets the log format which will be used by logs
382     specified in subsequent <directive>TransferLog</directive>
383     directives. The single argument can specify an explicit
384     <var>format</var> as discussed in the <a href="#formats">custom log
385     formats</a> section above. Alternatively, it can use a
386     <var>nickname</var> to refer to a log format defined in a
387     previous <directive>LogFormat</directive> directive as described
388     below.</p>
389
390     <p>The second form of the <directive>LogFormat</directive> 
391     directive associates an explicit <var>format</var> with a
392     <var>nickname</var>. This <var>nickname</var> can then be used in
393     subsequent <directive>LogFormat</directive> or
394     <directive module="mod_log_config">CustomLog</directive> directives
395     rather than repeating the entire format string. A
396     <directive>LogFormat</directive> directive that defines a nickname
397     <strong>does nothing else</strong> -- that is, it <em>only</em>
398     defines the nickname, it doesn't actually apply the format and make
399     it the default. Therefore, it will not affect subsequent
400     <directive module="mod_log_config">TransferLog</directive> directives.
401     In addition, <directive>LogFormat</directive> cannot use one nickname
402     to define another nickname. Note that the nickname should not contain
403     percent signs (<code>%</code>).</p>
404
405     <example><title>Example</title>
406       LogFormat "%v %h %l %u %t \"%r\" %&gt;s %b" vhost_common
407     </example>
408 </usage>
409 </directivesynopsis>
410
411 <directivesynopsis>
412 <name>TransferLog</name>
413 <description>Specify location of a log file</description>
414 <syntax>TransferLog <var>file</var>|<var>pipe</var></syntax>
415 <contextlist><context>server config</context><context>virtual host</context>
416 </contextlist>
417
418 <usage>
419     <p>This directive has exactly the same arguments and effect as
420     the <directive module="mod_log_config">CustomLog</directive>
421     directive, with the exception that it does not allow the log format
422     to be specified explicitly or for conditional logging of requests.
423     Instead, the log format is determined by the most recently specified
424     <directive module="mod_log_config">LogFormat</directive> directive
425     which does not define a nickname. Common Log Format is used if no
426     other format has been specified.</p>
427
428     <example><title>Example</title>
429       LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
430       TransferLog logs/access_log
431     </example>
432 </usage>
433 </directivesynopsis>
434
435 </modulesynopsis>