]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_log_config.html.en
New Module -- mod_logio.
[apache] / docs / manual / mod / mod_log_config.html.en
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
7       --><title>mod_log_config - Apache HTTP Server</title><link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /><link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /><link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link href="../images/favicon.ico" rel="shortcut icon" /></head><body><div id="page-header"><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><p class="apache">Apache HTTP Server Version 2.0</p><img alt="" src="../images/feather.gif" /></div><div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div><div id="path"><a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs-project/">Documentation</a> &gt; <a href="../">Version 2.0</a> &gt; <a href="./">Modules</a></div><div id="page-content"><div id="preamble"><h1>Apache Module mod_log_config</h1><table class="module"><tr><th><a href="module-dict.html#Description">Description:
8                   </a></th><td>Logging of the requests made to the server</td></tr><tr><th><a href="module-dict.html#Status">Status:
9                   </a></th><td>Base</td></tr><tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:
10                   </a></th><td>log_config_module</td></tr><tr><th><a href="module-dict.html#SourceFile">Source File:
11                   </a></th><td>mod_log_config.c</td></tr></table><h3>Summary</h3>
12
13     <p>This module provides for flexible logging of client
14     requests. Logs are written in a customizable format, and may be
15     written directly to a file, or to an external program.
16     Conditional logging is provided so that individual requests may
17     be included or excluded from the logs based on characteristics
18     of the request.</p>
19
20     <p>Three directives are provided by this module:
21     <code>TransferLog</code> to create a log file,
22     <code>LogFormat</code> to set a custom format, and
23     <code>CustomLog</code> to define a log file and format in one
24     step. The <code>TransferLog</code> and <code>CustomLog</code>
25     directives can be used multiple times in each server to cause
26     each request to be logged to multiple files.</p>
27 </div><div id="quickview"><h3 class="directives">Directives</h3><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#cookielog">CookieLog</a></li><li><img alt="" src="../images/down.gif" /> <a href="#customlog">CustomLog</a></li><li><img alt="" src="../images/down.gif" /> <a href="#logformat">LogFormat</a></li><li><img alt="" src="../images/down.gif" /> <a href="#transferlog">TransferLog</a></li></ul><h3>Topics</h3><ul id="topics"><li><img alt="" src="../images/down.gif" /> <a href="#formats">Custom Log Formats</a></li><li><img alt="" src="../images/down.gif" /> Security Considerations</li></ul><h3>See also</h3><ul class="seealso"><li><a href="../logs.html">Apache Log Files</a></li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="formats" id="formats">Custom Log Formats</a></h2>
28
29
30     <p>The format argument to the <code>LogFormat</code> and
31     <code>CustomLog</code> directives is a string. This string is
32     logged to the log file for each request. It can contain literal
33     characters copied into the log files and the c-type control
34     characters "\n" and "\t" to represent new-lines and tabs.
35     Literal quotes and back-slashes should be escaped with
36     back-slashes.</p>
37
38     <p>The characteristics of the request itself are logged by
39     placing "%" directives in the format string, which are replaced
40     in the log file by the values as follows:</p>
41
42 <table>
43
44 <tr><td>%...a:</td>          
45 <td>Remote IP-address</td></tr>
46
47 <tr><td>%...A:</td>          
48 <td>Local IP-address</td></tr>
49
50 <tr><td>%...B:</td>          
51 <td>Bytes sent, excluding HTTP headers.</td></tr>
52
53 <tr><td>%...b:</td>          
54 <td>Bytes sent, excluding HTTP headers. In CLF format
55 i.e. a '-' rather than a 0 when no bytes are sent.</td></tr>
56
57 <tr><td>%...{Foobar}C:</td>  
58 <td>The contents of cookie "Foobar" in the request sent to the server.</td></tr>
59
60 <tr><td>%...D:</td>          
61 <td>The time taken to serve the request, in microseconds.</td></tr>
62
63 <tr><td>%...{FOOBAR}e:</td>  
64 <td>The contents of the environment variable FOOBAR</td></tr>
65
66 <tr><td>%...f:</td>          
67 <td>Filename</td></tr>
68
69 <tr><td>%...h:</td>          
70 <td>Remote host</td></tr>
71
72 <tr><td>%...H</td>          
73 <td>The request protocol</td></tr>
74
75 <tr><td>%...{Foobar}i:</td>  
76 <td>The contents of Foobar: header line(s) in the request
77 sent to the server.</td></tr>
78
79 <tr><td>%...l:</td>          
80 <td>Remote logname (from identd, if supplied)</td></tr>
81
82 <tr><td>%...m:</td>          
83 <td>The request method</td></tr>
84
85 <tr><td>%...{Foobar}n:</td>  
86 <td>The contents of note "Foobar" from another module.</td></tr>
87
88 <tr><td>%...{Foobar}o:</td>  
89 <td>The contents of Foobar: header line(s) in the reply.</td></tr>
90
91 <tr><td>%...p:</td>          
92 <td>The canonical Port of the server serving the request</td></tr>
93
94 <tr><td>%...P:</td>          
95 <td>The process ID of the child that serviced the request.</td></tr>
96
97 <tr><td>%...q:</td>          
98 <td>The query string (prepended with a ? if a query string exists,
99 otherwise an empty string)</td></tr>
100
101 <tr><td>%...r:</td>          
102 <td>First line of request</td></tr>
103
104 <tr><td>%...s:</td>          
105 <td>Status.  For requests that got internally redirected, this is
106 the status of the *original* request --- %...&gt;s for the last.</td></tr>
107
108 <tr><td>%...t:</td>          
109 <td>Time, in common log format time format (standard english format)</td></tr>
110
111 <tr><td>%...{format}t:</td>  
112 <td>The time, in the form given by format, which should
113 be in strftime(3) format. (potentially localized)</td></tr>
114
115 <tr><td>%...T:</td>          
116 <td>The time taken to serve the request, in seconds.</td></tr>
117
118 <tr><td>%...u:</td>          
119 <td>Remote user (from auth; may be bogus if return status (%s) is 401)</td></tr>
120
121 <tr><td>%...U:</td>          
122 <td>The URL path requested, not including any query string.</td></tr>
123
124 <tr><td>%...v:</td>          
125 <td>The canonical ServerName of the server serving the request.</td></tr>
126
127 <tr><td>%...V:</td>          
128 <td>The server name according to the UseCanonicalName setting.</td></tr>
129
130 <tr><td>%...X:</td>          
131 <td>Connection status when response is completed.
132 <div class="example"><p><code>
133 'X' = connection aborted before the response completed.<br />
134 '+' = connection may be kept alive after the response is sent.<br />
135 '-' = connection will be closed after the response is sent.
136 </code></p></div>
137 <div class="note">(This directive was %...c in late versions of Apache 1.3, but
138 this conflicted with the historical ssl %...{var}c syntax.)</div>
139 </td></tr>
140
141 <tr><td>%...I:</td>          
142 <td>Bytes received, including request and headers, cannot be zero. You need to
143 enable <code class="module"><a
144 href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
145
146 <tr><td>%...O:</td>          
147 <td>Bytes sent, including headers, cannot be zero. You need to enable <code
148 class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use
149 this.</td></tr>
150
151 </table>
152
153     <p>The "..." can be nothing at all (<em>e.g.</em>, <code>"%h %u
154     %r %s %b"</code>), or it can indicate conditions for inclusion
155     of the item (which will cause it to be replaced with "-" if the
156     condition is not met). The forms of condition are a list of
157     HTTP status codes, which may or may not be preceded by "!".
158     Thus, "%400,501{User-agent}i" logs User-agent: on 400 errors
159     and 501 errors (Bad Request, Not Implemented) only;
160     "%!200,304,302{Referer}i" logs Referer: on all requests which
161     did <strong>not</strong> return some sort of normal status.</p>
162
163     <p>Note that there is no escaping performed on the strings from
164     %...r, %...i and %...o. This is mainly to comply with the
165     requirements of the Common Log Format. This implies that
166     clients can insert control characters into the log, so care
167     should be taken when dealing with raw log files.</p>
168
169     <p>Some commonly used log format strings are:</p>
170
171     <dl>
172       <dt>Common Log Format (CLF)</dt>
173
174       <dd><code>"%h %l %u %t \"%r\" %&gt;s %b"</code></dd>
175
176       <dt>Common Log Format with Virtual Host</dt>
177
178       <dd><code>"%v %h %l %u %t \"%r\" %&gt;s %b"</code></dd>
179
180       <dt>NCSA extended/combined log format</dt>
181
182       <dd><code>"%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\"
183       \"%{User-agent}i\""</code></dd>
184
185       <dt>Referer log format</dt>
186
187       <dd><code>"%{Referer}i -&gt; %U"</code></dd>
188
189       <dt>Agent (Browser) log format</dt>
190
191       <dd><code>"%{User-agent}i"</code></dd>
192     </dl>
193
194     <p>Note that the canonical <a href="core.html#servername">ServerName</a> and <a href="mpm_common.html#listen">Listen</a> of the server serving the
195     request are used for <code>%v</code> and <code>%p</code>
196     respectively. This happens regardless of the <a href="core.html#usecanonicalname">UseCanonicalName</a> setting
197     because otherwise log analysis programs would have to duplicate
198     the entire vhost matching algorithm in order to decide what
199     host really served the request.</p>
200     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2>Security Considerations</h2>
201
202     
203
204     <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
205     document for details on why your security could be compromised
206     if the directory where logfiles are stored is writable by
207     anyone other than the user that starts the server.</p>
208
209     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="CookieLog" id="CookieLog">CookieLog</a> <a name="cookielog" id="cookielog">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description: 
210               </a></th><td>Sets filename for the logging of cookies</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
211               </a></th><td>CookieLog <em>filename</em></td></tr><tr><th><a href="directive-dict.html#Context">Context:
212               </a></th><td>server config, virtual
213 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
214               </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
215               </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
216               </a></th><td>Only available in Apache 1.2 and above</td></tr></table>
217
218     <p>The <code class="directive">CookieLog</code> directive sets the 
219     filename for logging of cookies. The filename is relative to the
220     <code class="directive"><a href="../mod/core.html#serverroot">serverroot</a></code>. This directive is
221     included only for compatibility with <code class="module"><a href="../mod/mod_cookies.html">mod_cookies</a></code>,
222     and is deprecated.</p>
223 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="CustomLog" id="CustomLog">CustomLog</a> <a name="customlog" id="customlog">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description: 
224               </a></th><td>Sets filename and format of log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
225               </a></th><td>CustomLog 
226     <em>file</em>|<em>pipe</em> <em>format</em>|<em>nickname</em>
227     [env=[!]<em>environment-variable</em>]</td></tr><tr><th><a href="directive-dict.html#Context">Context:
228               </a></th><td>server config, virtual
229 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
230               </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
231               </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
232               </a></th><td>Nickname only available in Apache 1.3 or later.
233 Conditional logging available in 1.3.5 or later.</td></tr></table>
234     <p>The <code class="directive">CustomLog</code> directive is used to
235     log requests to the server. A log format is specified, and the
236     logging can optionally be made conditional on request
237     characteristics using environment variables.</p>
238
239     <p>The first argument, which specifies the location to which
240     the logs will be written, can take on one of the following two
241     types of values:</p>
242
243     <dl>
244       <dt><em>file</em></dt>
245
246       <dd>A filename, relative to the <a href="core.html#serverroot">ServerRoot</a>.</dd>
247
248       <dt><em>pipe</em></dt>
249
250       <dd>The pipe character "<code>|</code>", followed by the path
251       to a program to receive the log information on its standard
252       input. <strong>Security:</strong> if a program is used, then
253       it will be run under the user who started httpd. This will be
254       root if the server was started by root; be sure that the
255       program is secure.</dd>
256     </dl>
257
258     <p>The second argument specifies what will be written to the
259     log file. It can specify either a <em>nickname</em> defined by
260     a previous <a href="#logformat">LogFormat</a> directive, or it
261     can be an explicit <em>format</em> string as described in the
262     <a href="#formats">log formats</a> section.</p>
263
264     <p>For example, the following two sets of directives have
265     exactly the same effect:</p>
266
267 <div class="example"><p><code>
268      # CustomLog with format nickname<br />
269      LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common<br />
270      CustomLog logs/access_log common<br />
271 <br />
272      # CustomLog with explicit format string<br />
273      CustomLog logs/access_log "%h %l %u %t \"%r\" %&gt;s %b"<br />
274 </code></p></div>
275
276     <p>The third argument is optional and allows the decision on
277     whether or not to log a particular request to be based on the
278     presence or absence of a particular variable in the server
279     environment. If the specified <a href="../env.html">environment
280     variable</a> is set for the request (or is not set, in the case
281     of a '<code>env=!<em>name</em></code>' clause), then the
282     request will be logged.</p>
283
284     <p>Environment variables can be set on a <em>per</em>-request
285     basis using the <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
286     and/or <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> modules. For
287     example, if you want to record requests for all GIF
288     images on your server in a separate logfile but not in your main
289     log, you can use:</p>
290     
291 <div class="example"><p><code>
292     SetEnvIf Request_URI \.gif$ gif-image<br />
293     CustomLog gif-requests.log common env=gif-image<br />
294     CustomLog nongif-requests.log common env=!gif-image
295 </code></p></div>
296 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="LogFormat" id="LogFormat">LogFormat</a> <a name="logformat" id="logformat">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description: 
297               </a></th><td>Describes a format for use in a log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
298               </a></th><td>LogFormat
299     <em>format</em>|<em>nickname</em> [<em>nickname</em>]</td></tr><tr><th><a href="directive-dict.html#Default">Default: 
300               </a></th><td><code>LogFormat "%h %l %u %t \"%r\" %&gt;s %b"</code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
301               </a></th><td>server config, virtual
302 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
303               </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
304               </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
305               </a></th><td>Nickname only available in Apache 1.3 or later.
306 </td></tr></table>
307     <p>This directive specifies the format of the access log
308     file.</p>
309
310     <p>The <code class="directive">LogFormat</code> directive can take one of two
311     forms. In the first form, where only one argument is specified,
312     this directive sets the log format which will be used by logs
313     specified in subsequent <code class="directive">TransferLog</code>
314     directives. The single argument can specify an explicit
315     <em>format</em> as discussed in <a href="#formats">custom log
316     formats</a> section above. Alternatively, it can use a
317     <em>nickname</em> to refer to a log format defined in a
318     previous <code class="directive">LogFormat</code> directive as described
319     below.</p>
320
321     <p>The second form of the <code class="directive">LogFormat</code> 
322     directive associates an explicit <em>format</em> with a
323     <em>nickname</em>. This <em>nickname</em> can then be used in
324     subsequent <code class="directive">LogFormat</code> or
325     <code class="directive">CustomLog</code> directives rather than
326     repeating the entire format string. A
327     <code class="directive">LogFormat</code>
328     directive that defines a nickname <strong>does nothing
329     else</strong> -- that is, it <em>only</em> defines the
330     nickname, it doesn't actually apply the format and make it the
331     default. Therefore, it will not affect subsequent
332     <code class="directive">TransferLog</code> directives.  In addition,
333     <code class="directive">LogFormat</code> cannot use one nickname
334     to define another nickname.</p>
335
336     <p>For example:</p>
337
338     <div class="example"><p><code>LogFormat "%v %h %l %u %t \"%r\" %&gt;s %b"
339     vhost_common</code></p></div>
340
341 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="TransferLog" id="TransferLog">TransferLog</a> <a name="transferlog" id="transferlog">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description: 
342               </a></th><td>Specifly location of a log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
343               </a></th><td>TransferLog <em>file</em>|<em>pipe</em></td></tr><tr><th><a href="directive-dict.html#Context">Context:
344               </a></th><td>server config, virtual
345 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
346               </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
347               </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
348               </a></th><td /></tr></table>
349
350     <p>This directive has exactly the same arguments and effect as
351     the <code class="directive">CustomLog</code> directive, with the
352     exception that it does not allow the log format to be specified
353     explicitly or for conditional logging of requests. Instead, the
354     log format is determined by the most recently specified
355     <code class="directive">LogFormat</code> directive (which
356     does not define a nickname). Common Log Format is used if no
357     other format has been specified.</p>
358
359     <p>Example:</p>
360 <div class="example"><p><code>
361    LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
362    TransferLog logs/access_log
363 </code></p></div>
364
365 </div></div><div id="footer"><p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p><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></body></html>