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> |
26 <a href="../ko/mod/mod_log_config.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
28 <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>
29 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
30 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>log_config_module</td></tr>
31 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_log_config.c</td></tr></table>
34 <p>This module provides for flexible logging of client
35 requests. Logs are written in a customizable format, and may be
36 written directly to a file, or to an external program.
37 Conditional logging is provided so that individual requests may
38 be included or excluded from the logs based on characteristics
41 <p>Three directives are provided by this module:
42 <code class="directive"><a href="#transferlog">TransferLog</a></code> to create
43 a log file, <code class="directive"><a href="#logformat">LogFormat</a></code>
44 to set a custom format, and <code class="directive"><a href="#customlog">CustomLog</a></code> to define a log file and format in one
45 step. The <code class="directive">TransferLog</code> and <code class="directive">CustomLog</code> directives can be used multiple times in each
46 server to cause each request to be logged to multiple files.</p>
48 <div id="quickview"><h3 class="directives">Directives</h3>
50 <li><img alt="" src="../images/down.gif" /> <a href="#cookielog">CookieLog</a></li>
51 <li><img alt="" src="../images/down.gif" /> <a href="#customlog">CustomLog</a></li>
52 <li><img alt="" src="../images/down.gif" /> <a href="#logformat">LogFormat</a></li>
53 <li><img alt="" src="../images/down.gif" /> <a href="#transferlog">TransferLog</a></li>
57 <li><img alt="" src="../images/down.gif" /> <a href="#formats">Custom Log Formats</a></li>
58 <li><img alt="" src="../images/down.gif" /> <a href="#security">Security Considerations</a></li>
59 </ul><h3>See also</h3>
61 <li><a href="../logs.html">Apache Log Files</a></li>
63 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
65 <h2><a name="formats" id="formats">Custom Log Formats</a></h2>
67 <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
68 used to log each request to the log file. It can contain literal
69 characters copied into the log files and the C-style control
70 characters "\n" and "\t" to represent new-lines and tabs.
71 Literal quotes and back-slashes should be escaped with
74 <p>The characteristics of the request itself are logged by
75 placing "<code>%</code>" directives in the format string, which are
76 replaced in the log file by the values as follows:</p>
78 <table class="bordered"><tr class="header"><th>Format String</th>
79 <th>Description</th></tr>
80 <tr><td><code>%%</code></td>
81 <td>The percent sign</td></tr>
82 <tr class="odd"><td><code>%...a</code></td>
83 <td>Remote IP-address</td></tr>
84 <tr><td><code>%...A</code></td>
85 <td>Local IP-address</td></tr>
86 <tr class="odd"><td><code>%...B</code></td>
87 <td>Bytes sent, excluding HTTP headers.</td></tr>
88 <tr><td><code>%...b</code></td>
89 <td>Bytes sent, excluding HTTP headers. In CLF format, <em>i.e.</em>
90 a '<code>-</code>' rather than a 0 when no bytes are sent.</td></tr>
91 <tr class="odd"><td><code>%...{<var>Foobar</var>}C</code></td>
92 <td>The contents of cookie <var>Foobar</var> in the request sent
93 to the server.</td></tr>
94 <tr><td><code>%...D</code></td>
95 <td>The time taken to serve the request, in microseconds.</td></tr>
96 <tr class="odd"><td><code>%...{<var>FOOBAR</var>}e</code></td>
97 <td>The contents of the environment variable
98 <var>FOOBAR</var></td></tr>
99 <tr><td><code>%...f</code></td>
100 <td>Filename</td></tr>
101 <tr class="odd"><td><code>%...h</code></td>
102 <td>Remote host</td></tr>
103 <tr><td><code>%...H</code></td>
104 <td>The request protocol</td></tr>
105 <tr class="odd"><td><code>%...{<var>Foobar</var>}i</code></td>
106 <td>The contents of <code><var>Foobar</var>:</code> header line(s)
107 in the request sent to the server.</td></tr>
108 <tr><td><code>%...l</code></td>
109 <td>Remote logname (from identd, if supplied). This will return a
110 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
111 <code>On</code>.</td></tr>
112 <tr class="odd"><td><code>%...m</code></td>
113 <td>The request method</td></tr>
114 <tr><td><code>%...{<var>Foobar</var>}n</code></td>
115 <td>The contents of note <var>Foobar</var> from another
117 <tr class="odd"><td><code>%...{<var>Foobar</var>}o</code></td>
118 <td>The contents of <code><var>Foobar</var>:</code> header line(s)
119 in the reply.</td></tr>
120 <tr><td><code>%...p</code></td>
121 <td>The canonical port of the server serving the request</td></tr>
122 <tr class="odd"><td><code>%...P</code></td>
123 <td>The process ID of the child that serviced the request.</td></tr>
124 <tr><td><code>%...{<var>format</var>}P</code></td>
125 <td>The process ID or thread id of the child that serviced the
126 request. Valid formats are <code>pid</code> and <code>tid</code>.
128 <tr class="odd"><td><code>%...q</code></td>
129 <td>The query string (prepended with a <code>?</code> if a query
130 string exists, otherwise an empty string)</td></tr>
131 <tr><td><code>%...r</code></td>
132 <td>First line of request</td></tr>
133 <tr class="odd"><td><code>%...s</code></td>
134 <td>Status. For requests that got internally redirected, this is
135 the status of the *original* request --- <code>%...>s</code>
136 for the last.</td></tr>
137 <tr><td><code>%...t</code></td>
138 <td>Time, in common log format time format (standard english
140 <tr class="odd"><td><code>%...{<var>format</var>}t</code></td>
141 <td>The time, in the form given by format, which should be in
142 <code>strftime(3)</code> format. (potentially localized)</td></tr>
143 <tr><td><code>%...T</code></td>
144 <td>The time taken to serve the request, in seconds.</td></tr>
145 <tr class="odd"><td><code>%...u</code></td>
146 <td>Remote user (from auth; may be bogus if return status
147 (<code>%s</code>) is 401)</td></tr>
148 <tr><td><code>%...U</code></td>
149 <td>The URL path requested, not including any query string.</td></tr>
150 <tr class="odd"><td><code>%...v</code></td>
151 <td>The canonical <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
152 of the server serving the request.</td></tr>
153 <tr><td><code>%...V</code></td>
154 <td>The server name according to the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> setting.</td></tr>
155 <tr class="odd"><td><code>%...X</code></td>
156 <td>Connection status when response is completed:
160 <tr><td><code>X</code> =</td>
161 <td>connection aborted before the response completed.</td></tr>
162 <tr><td><code>+</code> =</td>
163 <td>connection may be kept alive after the response is
165 <tr><td><code>-</code> = </td>
166 <td>connection will be closed after the response is
170 <p>(This directive was <code>%...c</code> in late versions of Apache
171 1.3, but this conflicted with the historical ssl
172 <code>%...{<var>var</var>}c</code> syntax.)</p></td></tr>
173 <tr><td><code>%...I</code></td>
174 <td>Bytes received, including request and headers, cannot be zero.
175 You need to enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
176 <tr class="odd"><td><code>%...O</code></td>
177 <td>Bytes sent, including headers, cannot be zero. You need to
178 enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
181 <p>The "<var>...</var>" can be nothing at all (<em>e.g.</em>,
182 <code>"%h %u %r %s %b"</code>), or it can indicate conditions for
183 inclusion of the item (which will cause it to be replaced with "-" if
184 the condition is not met). The forms of condition are a list of
185 HTTP status codes, which may or may not be preceded by "!".
186 Thus, "%400,501{User-agent}i" logs <code>User-agent:</code> on 400
187 errors and 501 errors (Bad Request, Not Implemented) only;
188 "%!200,304,302{Referer}i" logs <code>Referer:</code> on all requests
189 which did <em>not</em> return some sort of normal status.</p>
191 <p>The modifiers "<" and ">" can be used for requests that
192 have been internally redirected to choose whether the original or
193 final (respectively) request should be consulted. By default, the
194 <code>%</code> directives <code>%s, %U, %T, %D,</code> and
195 <code>%r</code> look at the original request while all others look
196 at the final request. So for example, <code>%>s</code> can be
197 used to record the final status of the request and
198 <code>%<u</code> can be used to record the original
199 authenticated user on a request that is internally redirected to an
200 unauthenticated resource.</p>
202 <p>Note that in httpd 2.0 versions prior to 2.0.46, no escaping was performed
203 on the strings from <code>%...r</code>, <code>%...i</code> and
204 <code>%...o</code>. This was mainly to comply with the requirements of
205 the Common Log Format. This implied that clients could insert control
206 characters into the log, so you had to be quite careful when dealing
207 with raw log files.</p>
209 <p>For security reasons, starting with 2.0.46, non-printable and
210 other special characters are escaped mostly by using
211 <code>\x<var>hh</var></code> sequences, where <var>hh</var> stands for
212 the hexadecimal representation of the raw byte. Exceptions from this
213 rule are <code>"</code> and <code>\</code> which are escaped by prepending
214 a backslash, and all whitespace characters which are written in their
215 C-style notation (<code>\n</code>, <code>\t</code> etc).</p>
217 <p>Some commonly used log format strings are:</p>
220 <dt>Common Log Format (CLF)</dt>
221 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
223 <dt>Common Log Format with Virtual Host</dt>
224 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
226 <dt>NCSA extended/combined log format</dt>
227 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
228 \"%{User-agent}i\""</code></dd>
230 <dt>Referer log format</dt>
231 <dd><code>"%{Referer}i -> %U"</code></dd>
233 <dt>Agent (Browser) log format</dt>
234 <dd><code>"%{User-agent}i"</code></dd>
237 <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
238 request are used for <code>%v</code> and <code>%p</code>
239 respectively. This happens regardless of the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> setting
240 because otherwise log analysis programs would have to duplicate
241 the entire vhost matching algorithm in order to decide what
242 host really served the request.</p>
243 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
244 <div class="section">
245 <h2><a name="security" id="security">Security Considerations</a></h2>
246 <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
247 document for details on why your security could be compromised
248 if the directory where logfiles are stored is writable by
249 anyone other than the user that starts the server.</p>
251 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
252 <div class="directive-section"><h2><a name="CookieLog" id="CookieLog">CookieLog</a> <a name="cookielog" id="cookielog">Directive</a></h2>
253 <table class="directive">
254 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename for the logging of cookies</td></tr>
255 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CookieLog <var>filename</var></code></td></tr>
256 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
257 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
258 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
259 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>This directive is deprecated.</td></tr>
261 <p>The <code class="directive">CookieLog</code> directive sets the
262 filename for logging of cookies. The filename is relative to the
263 <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>. This directive is
264 included only for compatibility with <code>mod_cookies</code>,
265 and is deprecated.</p>
268 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
269 <div class="directive-section"><h2><a name="CustomLog" id="CustomLog">CustomLog</a> <a name="customlog" id="customlog">Directive</a></h2>
270 <table class="directive">
271 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename and format of log file</td></tr>
272 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CustomLog <var>file</var>|<var>pipe</var>
273 <var>format</var>|<var>nickname</var>
274 [env=[!]<var>environment-variable</var>]</code></td></tr>
275 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
276 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
277 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
279 <p>The <code class="directive">CustomLog</code> directive is used to
280 log requests to the server. A log format is specified, and the
281 logging can optionally be made conditional on request
282 characteristics using environment variables.</p>
284 <p>The first argument, which specifies the location to which
285 the logs will be written, can take one of the following two
289 <dt><var>file</var></dt>
290 <dd>A filename, relative to the <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>.</dd>
292 <dt><var>pipe</var></dt>
293 <dd>The pipe character "<code>|</code>", followed by the path
294 to a program to receive the log information on its standard
297 <div class="warning"><h3>Security:</h3>
298 <p>If a program is used, then it will be run as the user who
299 started <code class="program"><a href="../programs/httpd.html">httpd</a></code>. This will be root if the server was
300 started by root; be sure that the program is secure.</p>
302 <div class="warning"><h3>Note</h3>
303 <p>When entering a file path on non-Unix platforms, care should be taken
304 to make sure that only forward slashed are used even though the platform
305 may allow the use of back slashes. In general it is a good idea to always
306 use forward slashes throughout the configuration files.</p>
310 <p>The second argument specifies what will be written to the
311 log file. It can specify either a <var>nickname</var> defined by
312 a previous <code class="directive"><a href="#logformat">LogFormat</a></code>
313 directive, or it can be an explicit <var>format</var> string as
314 described in the <a href="#formats">log formats</a> section.</p>
316 <p>For example, the following two sets of directives have
317 exactly the same effect:</p>
319 <div class="example"><p><code>
320 # CustomLog with format nickname<br />
321 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
322 CustomLog logs/access_log common<br />
324 # CustomLog with explicit format string<br />
325 CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"
328 <p>The third argument is optional and controls whether or
329 not to log a particular request based on the
330 presence or absence of a particular variable in the server
331 environment. If the specified <a href="../env.html">environment
332 variable</a> is set for the request (or is not set, in the case
333 of a '<code>env=!<var>name</var></code>' clause), then the
334 request will be logged.</p>
336 <p>Environment variables can be set on a per-request
337 basis using the <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
338 and/or <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> modules. For
339 example, if you want to record requests for all GIF
340 images on your server in a separate logfile but not in your main
341 log, you can use:</p>
343 <div class="example"><p><code>
344 SetEnvIf Request_URI \.gif$ gif-image<br />
345 CustomLog gif-requests.log common env=gif-image<br />
346 CustomLog nongif-requests.log common env=!gif-image
350 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
351 <div class="directive-section"><h2><a name="LogFormat" id="LogFormat">LogFormat</a> <a name="logformat" id="logformat">Directive</a></h2>
352 <table class="directive">
353 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Describes a format for use in a log file</td></tr>
354 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LogFormat <var>format</var>|<var>nickname</var>
355 [<var>nickname</var>]</code></td></tr>
356 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LogFormat "%h %l %u %t \"%r\" %>s %b"</code></td></tr>
357 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
358 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
359 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
361 <p>This directive specifies the format of the access log
364 <p>The <code class="directive">LogFormat</code> directive can take one of two
365 forms. In the first form, where only one argument is specified,
366 this directive sets the log format which will be used by logs
367 specified in subsequent <code class="directive">TransferLog</code>
368 directives. The single argument can specify an explicit
369 <var>format</var> as discussed in the <a href="#formats">custom log
370 formats</a> section above. Alternatively, it can use a
371 <var>nickname</var> to refer to a log format defined in a
372 previous <code class="directive">LogFormat</code> directive as described
375 <p>The second form of the <code class="directive">LogFormat</code>
376 directive associates an explicit <var>format</var> with a
377 <var>nickname</var>. This <var>nickname</var> can then be used in
378 subsequent <code class="directive">LogFormat</code> or
379 <code class="directive"><a href="#customlog">CustomLog</a></code> directives
380 rather than repeating the entire format string. A
381 <code class="directive">LogFormat</code> directive that defines a nickname
382 <strong>does nothing else</strong> -- that is, it <em>only</em>
383 defines the nickname, it doesn't actually apply the format and make
384 it the default. Therefore, it will not affect subsequent
385 <code class="directive"><a href="#transferlog">TransferLog</a></code> directives.
386 In addition, <code class="directive">LogFormat</code> cannot use one nickname
387 to define another nickname. Note that the nickname should not contain
388 percent signs (<code>%</code>).</p>
390 <div class="example"><h3>Example</h3><p><code>
391 LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
395 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
396 <div class="directive-section"><h2><a name="TransferLog" id="TransferLog">TransferLog</a> <a name="transferlog" id="transferlog">Directive</a></h2>
397 <table class="directive">
398 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify location of a log file</td></tr>
399 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>TransferLog <var>file</var>|<var>pipe</var></code></td></tr>
400 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
401 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
402 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
404 <p>This directive has exactly the same arguments and effect as
405 the <code class="directive"><a href="#customlog">CustomLog</a></code>
406 directive, with the exception that it does not allow the log format
407 to be specified explicitly or for conditional logging of requests.
408 Instead, the log format is determined by the most recently specified
409 <code class="directive"><a href="#logformat">LogFormat</a></code> directive
410 which does not define a nickname. Common Log Format is used if no
411 other format has been specified.</p>
413 <div class="example"><h3>Example</h3><p><code>
414 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
415 TransferLog logs/access_log
420 <div class="bottomlang">
421 <p><span>Available Languages: </span><a href="../en/mod/mod_log_config.html" title="English"> en </a> |
422 <a href="../ja/mod/mod_log_config.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
423 <a href="../ko/mod/mod_log_config.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
424 </div><div id="footer">
425 <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>
426 <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>