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>Note that in httpd 2.0 versions prior to 2.0.46, no escaping was performed
191 on the strings from <code>%...r</code>, <code>%...i</code> and
192 <code>%...o</code>. This was mainly to comply with the requirements of
193 the Common Log Format. This implied that clients could insert control
194 characters into the log, so you had to be quite careful when dealing
195 with raw log files.</p>
197 <p>For security reasons, starting with 2.0.46, non-printable and
198 other special characters are escaped mostly by using
199 <code>\x<var>hh</var></code> sequences, where <var>hh</var> stands for
200 the hexadecimal representation of the raw byte. Exceptions from this
201 rule are <code>"</code> and <code>\</code> which are escaped by prepending
202 a backslash, and all whitespace characters which are written in their
203 C-style notation (<code>\n</code>, <code>\t</code> etc).</p>
205 <p>Some commonly used log format strings are:</p>
208 <dt>Common Log Format (CLF)</dt>
209 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
211 <dt>Common Log Format with Virtual Host</dt>
212 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
214 <dt>NCSA extended/combined log format</dt>
215 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
216 \"%{User-agent}i\""</code></dd>
218 <dt>Referer log format</dt>
219 <dd><code>"%{Referer}i -> %U"</code></dd>
221 <dt>Agent (Browser) log format</dt>
222 <dd><code>"%{User-agent}i"</code></dd>
225 <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
226 request are used for <code>%v</code> and <code>%p</code>
227 respectively. This happens regardless of the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> setting
228 because otherwise log analysis programs would have to duplicate
229 the entire vhost matching algorithm in order to decide what
230 host really served the request.</p>
231 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
232 <div class="section">
233 <h2><a name="security" id="security">Security Considerations</a></h2>
234 <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
235 document for details on why your security could be compromised
236 if the directory where logfiles are stored is writable by
237 anyone other than the user that starts the server.</p>
239 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
240 <div class="directive-section"><h2><a name="CookieLog" id="CookieLog">CookieLog</a> <a name="cookielog" id="cookielog">Directive</a></h2>
241 <table class="directive">
242 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename for the logging of cookies</td></tr>
243 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CookieLog <var>filename</var></code></td></tr>
244 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
245 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
246 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
247 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>This directive is deprecated.</td></tr>
249 <p>The <code class="directive">CookieLog</code> directive sets the
250 filename for logging of cookies. The filename is relative to the
251 <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>. This directive is
252 included only for compatibility with <code>mod_cookies</code>,
253 and is deprecated.</p>
256 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
257 <div class="directive-section"><h2><a name="CustomLog" id="CustomLog">CustomLog</a> <a name="customlog" id="customlog">Directive</a></h2>
258 <table class="directive">
259 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename and format of log file</td></tr>
260 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CustomLog <var>file</var>|<var>pipe</var>
261 <var>format</var>|<var>nickname</var>
262 [env=[!]<var>environment-variable</var>]</code></td></tr>
263 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
264 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
265 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
267 <p>The <code class="directive">CustomLog</code> directive is used to
268 log requests to the server. A log format is specified, and the
269 logging can optionally be made conditional on request
270 characteristics using environment variables.</p>
272 <p>The first argument, which specifies the location to which
273 the logs will be written, can take one of the following two
277 <dt><var>file</var></dt>
278 <dd>A filename, relative to the <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>.</dd>
280 <dt><var>pipe</var></dt>
281 <dd>The pipe character "<code>|</code>", followed by the path
282 to a program to receive the log information on its standard
285 <div class="warning"><h3>Security:</h3>
286 <p>If a program is used, then it will be run as the user who
287 started httpd. This will be root if the server was started by root;
288 be sure that the program is secure.</p>
290 <div class="warning"><h3>Note</h3>
291 <p>When entering a file path on non-Unix platforms, care should be taken
292 to make sure that only forward slashed are used even though the platform
293 may allow the use of back slashes. In general it is a good idea to always
294 use forward slashes throughout the configuration files.</p>
298 <p>The second argument specifies what will be written to the
299 log file. It can specify either a <var>nickname</var> defined by
300 a previous <code class="directive"><a href="#logformat">LogFormat</a></code>
301 directive, or it can be an explicit <var>format</var> string as
302 described in the <a href="#formats">log formats</a> section.</p>
304 <p>For example, the following two sets of directives have
305 exactly the same effect:</p>
307 <div class="example"><p><code>
308 # CustomLog with format nickname<br />
309 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
310 CustomLog logs/access_log common<br />
312 # CustomLog with explicit format string<br />
313 CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"
316 <p>The third argument is optional and controls whether or
317 not to log a particular request based on the
318 presence or absence of a particular variable in the server
319 environment. If the specified <a href="../env.html">environment
320 variable</a> is set for the request (or is not set, in the case
321 of a '<code>env=!<var>name</var></code>' clause), then the
322 request will be logged.</p>
324 <p>Environment variables can be set on a per-request
325 basis using the <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
326 and/or <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> modules. For
327 example, if you want to record requests for all GIF
328 images on your server in a separate logfile but not in your main
329 log, you can use:</p>
331 <div class="example"><p><code>
332 SetEnvIf Request_URI \.gif$ gif-image<br />
333 CustomLog gif-requests.log common env=gif-image<br />
334 CustomLog nongif-requests.log common env=!gif-image
338 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
339 <div class="directive-section"><h2><a name="LogFormat" id="LogFormat">LogFormat</a> <a name="logformat" id="logformat">Directive</a></h2>
340 <table class="directive">
341 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Describes a format for use in a log file</td></tr>
342 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LogFormat <var>format</var>|<var>nickname</var>
343 [<var>nickname</var>]</code></td></tr>
344 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LogFormat "%h %l %u %t \"%r\" %>s %b"</code></td></tr>
345 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
346 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
347 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
349 <p>This directive specifies the format of the access log
352 <p>The <code class="directive">LogFormat</code> directive can take one of two
353 forms. In the first form, where only one argument is specified,
354 this directive sets the log format which will be used by logs
355 specified in subsequent <code class="directive">TransferLog</code>
356 directives. The single argument can specify an explicit
357 <var>format</var> as discussed in the <a href="#formats">custom log
358 formats</a> section above. Alternatively, it can use a
359 <var>nickname</var> to refer to a log format defined in a
360 previous <code class="directive">LogFormat</code> directive as described
363 <p>The second form of the <code class="directive">LogFormat</code>
364 directive associates an explicit <var>format</var> with a
365 <var>nickname</var>. This <var>nickname</var> can then be used in
366 subsequent <code class="directive">LogFormat</code> or
367 <code class="directive"><a href="#customlog">CustomLog</a></code> directives
368 rather than repeating the entire format string. A
369 <code class="directive">LogFormat</code> directive that defines a nickname
370 <strong>does nothing else</strong> -- that is, it <em>only</em>
371 defines the nickname, it doesn't actually apply the format and make
372 it the default. Therefore, it will not affect subsequent
373 <code class="directive"><a href="#transferlog">TransferLog</a></code> directives.
374 In addition, <code class="directive">LogFormat</code> cannot use one nickname
375 to define another nickname. Note that the nickname should not contain
376 percent signs (<code>%</code>).</p>
378 <div class="example"><h3>Example</h3><p><code>
379 LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
383 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
384 <div class="directive-section"><h2><a name="TransferLog" id="TransferLog">TransferLog</a> <a name="transferlog" id="transferlog">Directive</a></h2>
385 <table class="directive">
386 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify location of a log file</td></tr>
387 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>TransferLog <var>file</var>|<var>pipe</var></code></td></tr>
388 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
389 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
390 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
392 <p>This directive has exactly the same arguments and effect as
393 the <code class="directive"><a href="#customlog">CustomLog</a></code>
394 directive, with the exception that it does not allow the log format
395 to be specified explicitly or for conditional logging of requests.
396 Instead, the log format is determined by the most recently specified
397 <code class="directive"><a href="#logformat">LogFormat</a></code> directive
398 which does not define a nickname. Common Log Format is used if no
399 other format has been specified.</p>
401 <div class="example"><h3>Example</h3><p><code>
402 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
403 TransferLog logs/access_log
408 <div class="bottomlang">
409 <p><span>Available Languages: </span><a href="../en/mod/mod_log_config.html" title="English"> en </a> |
410 <a href="../ja/mod/mod_log_config.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
411 </div><div id="footer">
412 <p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p>
413 <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>