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="<-" alt="<-" src="../images/left.gif" /></a></div><div id="path"><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.0</a> > <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>
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
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>
28 <li><img alt="" src="../images/down.gif" /> <a href="#customlog">CustomLog</a></li>
29 <li><img alt="" src="../images/down.gif" /> <a href="#logformat">LogFormat</a></li>
30 <li><img alt="" src="../images/down.gif" /> <a href="#transferlog">TransferLog</a></li>
31 </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" /> <a href="#security">Security Considerations</a></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>
34 <p>The format argument to the <code>LogFormat</code> and
35 <code>CustomLog</code> directives is a string. This string is
36 logged to the log file for each request. It can contain literal
37 characters copied into the log files and the c-type control
38 characters "\n" and "\t" to represent new-lines and tabs.
39 Literal quotes and back-slashes should be escaped with
42 <p>The characteristics of the request itself are logged by
43 placing "%" directives in the format string, which are replaced
44 in the log file by the values as follows:</p>
49 <td>Remote IP-address</td></tr>
52 <td>Local IP-address</td></tr>
55 <td>Bytes sent, excluding HTTP headers.</td></tr>
58 <td>Bytes sent, excluding HTTP headers. In CLF format
59 i.e. a '-' rather than a 0 when no bytes are sent.</td></tr>
61 <tr><td>%...{Foobar}C:</td>
62 <td>The contents of cookie "Foobar" in the request sent to the server.</td></tr>
65 <td>The time taken to serve the request, in microseconds.</td></tr>
67 <tr><td>%...{FOOBAR}e:</td>
68 <td>The contents of the environment variable FOOBAR</td></tr>
71 <td>Filename</td></tr>
74 <td>Remote host</td></tr>
77 <td>The request protocol</td></tr>
79 <tr><td>%...{Foobar}i:</td>
80 <td>The contents of Foobar: header line(s) in the request
81 sent to the server.</td></tr>
84 <td>Remote logname (from identd, if supplied)</td></tr>
87 <td>The request method</td></tr>
89 <tr><td>%...{Foobar}n:</td>
90 <td>The contents of note "Foobar" from another module.</td></tr>
92 <tr><td>%...{Foobar}o:</td>
93 <td>The contents of Foobar: header line(s) in the reply.</td></tr>
96 <td>The canonical Port of the server serving the request</td></tr>
99 <td>The process ID of the child that serviced the request.</td></tr>
102 <td>The query string (prepended with a ? if a query string exists,
103 otherwise an empty string)</td></tr>
106 <td>First line of request</td></tr>
109 <td>Status. For requests that got internally redirected, this is
110 the status of the *original* request --- %...>s for the last.</td></tr>
113 <td>Time, in common log format time format (standard english format)</td></tr>
115 <tr><td>%...{format}t:</td>
116 <td>The time, in the form given by format, which should
117 be in strftime(3) format. (potentially localized)</td></tr>
120 <td>The time taken to serve the request, in seconds.</td></tr>
123 <td>Remote user (from auth; may be bogus if return status (%s) is 401)</td></tr>
126 <td>The URL path requested, not including any query string.</td></tr>
129 <td>The canonical ServerName of the server serving the request.</td></tr>
132 <td>The server name according to the UseCanonicalName setting.</td></tr>
135 <td>Connection status when response is completed.
136 <div class="example"><p><code>
137 'X' = connection aborted before the response completed.<br />
138 '+' = connection may be kept alive after the response is sent.<br />
139 '-' = connection will be closed after the response is sent.
141 <div class="note">(This directive was %...c in late versions of Apache 1.3, but
142 this conflicted with the historical ssl %...{var}c syntax.)</div>
146 <td>Bytes received, including request and headers, cannot be zero. You need to
147 enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
150 <td>Bytes sent, including headers, cannot be zero. You need to enable
151 <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
155 <p>The "..." can be nothing at all (<em>e.g.</em>, <code>"%h %u
156 %r %s %b"</code>), or it can indicate conditions for inclusion
157 of the item (which will cause it to be replaced with "-" if the
158 condition is not met). The forms of condition are a list of
159 HTTP status codes, which may or may not be preceded by "!".
160 Thus, "%400,501{User-agent}i" logs User-agent: on 400 errors
161 and 501 errors (Bad Request, Not Implemented) only;
162 "%!200,304,302{Referer}i" logs Referer: on all requests which
163 did <strong>not</strong> return some sort of normal status.</p>
165 <p>Note that there is no escaping performed on the strings from
166 %...r, %...i and %...o. This is mainly to comply with the
167 requirements of the Common Log Format. This implies that
168 clients can insert control characters into the log, so care
169 should be taken when dealing with raw log files.</p>
171 <p>Some commonly used log format strings are:</p>
174 <dt>Common Log Format (CLF)</dt>
176 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
178 <dt>Common Log Format with Virtual Host</dt>
180 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
182 <dt>NCSA extended/combined log format</dt>
184 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
185 \"%{User-agent}i\""</code></dd>
187 <dt>Referer log format</dt>
189 <dd><code>"%{Referer}i -> %U"</code></dd>
191 <dt>Agent (Browser) log format</dt>
193 <dd><code>"%{User-agent}i"</code></dd>
196 <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
197 request are used for <code>%v</code> and <code>%p</code>
198 respectively. This happens regardless of the <a href="core.html#usecanonicalname">UseCanonicalName</a> setting
199 because otherwise log analysis programs would have to duplicate
200 the entire vhost matching algorithm in order to decide what
201 host really served the request.</p>
202 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="security" id="security">Security Considerations</a></h2>
206 <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
207 document for details on why your security could be compromised
208 if the directory where logfiles are stored is writable by
209 anyone other than the user that starts the server.</p>
211 </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:
212 </a></th><td>Sets filename for the logging of cookies</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
213 </a></th><td><code>CookieLog <em>filename</em></code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
214 </a></th><td>server config, virtual host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
215 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
216 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
217 </a></th><td>Only available in Apache 1.2 and above</td></tr></table>
219 <p>The <code class="directive">CookieLog</code> directive sets the
220 filename for logging of cookies. The filename is relative to the
221 <code class="directive"><a href="../mod/core.html#serverroot">serverroot</a></code>. This directive is
222 included only for compatibility with <code class="module"><a href="../mod/mod_cookies.html">mod_cookies</a></code>,
223 and is deprecated.</p>
224 </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:
225 </a></th><td>Sets filename and format of log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
226 </a></th><td><code>CustomLog
227 <em>file</em>|<em>pipe</em> <em>format</em>|<em>nickname</em>
228 [env=[!]<em>environment-variable</em>]</code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
229 </a></th><td>server config, virtual 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>
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
244 <dt><em>file</em></dt>
246 <dd>A filename, relative to the <a href="core.html#serverroot">ServerRoot</a>.</dd>
248 <dt><em>pipe</em></dt>
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>
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>
264 <p>For example, the following two sets of directives have
265 exactly the same effect:</p>
267 <div class="example"><p><code>
268 # CustomLog with format nickname<br />
269 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
270 CustomLog logs/access_log common<br />
272 # CustomLog with explicit format string<br />
273 CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"<br />
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>
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>
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
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><code>LogFormat
299 <em>format</em>|<em>nickname</em> [<em>nickname</em>]</code></td></tr><tr><th><a href="directive-dict.html#Default">Default:
300 </a></th><td><code>LogFormat "%h %l %u %t \"%r\" %>s %b"</code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
301 </a></th><td>server config, virtual host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
302 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
303 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
304 </a></th><td>Nickname only available in Apache 1.3 or later.
306 <p>This directive specifies the format of the access log
309 <p>The <code class="directive">LogFormat</code> directive can take one of two
310 forms. In the first form, where only one argument is specified,
311 this directive sets the log format which will be used by logs
312 specified in subsequent <code class="directive">TransferLog</code>
313 directives. The single argument can specify an explicit
314 <em>format</em> as discussed in <a href="#formats">custom log
315 formats</a> section above. Alternatively, it can use a
316 <em>nickname</em> to refer to a log format defined in a
317 previous <code class="directive">LogFormat</code> directive as described
320 <p>The second form of the <code class="directive">LogFormat</code>
321 directive associates an explicit <em>format</em> with a
322 <em>nickname</em>. This <em>nickname</em> can then be used in
323 subsequent <code class="directive">LogFormat</code> or
324 <code class="directive">CustomLog</code> directives rather than
325 repeating the entire format string. A
326 <code class="directive">LogFormat</code>
327 directive that defines a nickname <strong>does nothing
328 else</strong> -- that is, it <em>only</em> defines the
329 nickname, it doesn't actually apply the format and make it the
330 default. Therefore, it will not affect subsequent
331 <code class="directive">TransferLog</code> directives. In addition,
332 <code class="directive">LogFormat</code> cannot use one nickname
333 to define another nickname.</p>
337 <div class="example"><p><code>LogFormat "%v %h %l %u %t \"%r\" %>s %b"
338 vhost_common</code></p></div>
340 </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:
341 </a></th><td>Specifly location of a log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
342 </a></th><td><code>TransferLog <em>file</em>|<em>pipe</em></code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
343 </a></th><td>server config, virtual host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
344 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
345 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
346 </a></th><td /></tr></table>
348 <p>This directive has exactly the same arguments and effect as
349 the <code class="directive">CustomLog</code> directive, with the
350 exception that it does not allow the log format to be specified
351 explicitly or for conditional logging of requests. Instead, the
352 log format is determined by the most recently specified
353 <code class="directive">LogFormat</code> directive (which
354 does not define a nickname). Common Log Format is used if no
355 other format has been specified.</p>
358 <div class="example"><p><code>
359 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
360 TransferLog logs/access_log
363 </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>