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><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>
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
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>
45 <td>Remote IP-address</td></tr>
48 <td>Local IP-address</td></tr>
51 <td>Bytes sent, excluding HTTP headers.</td></tr>
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>
57 <tr><td>%...{Foobar}C:</td>
58 <td>The contents of cookie "Foobar" in the request sent to the server.</td></tr>
61 <td>The time taken to serve the request, in microseconds.</td></tr>
63 <tr><td>%...{FOOBAR}e:</td>
64 <td>The contents of the environment variable FOOBAR</td></tr>
67 <td>Filename</td></tr>
70 <td>Remote host</td></tr>
73 <td>The request protocol</td></tr>
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>
80 <td>Remote logname (from identd, if supplied)</td></tr>
83 <td>The request method</td></tr>
85 <tr><td>%...{Foobar}n:</td>
86 <td>The contents of note "Foobar" from another module.</td></tr>
88 <tr><td>%...{Foobar}o:</td>
89 <td>The contents of Foobar: header line(s) in the reply.</td></tr>
92 <td>The canonical Port of the server serving the request</td></tr>
95 <td>The process ID of the child that serviced the request.</td></tr>
98 <td>The query string (prepended with a ? if a query string exists,
99 otherwise an empty string)</td></tr>
102 <td>First line of request</td></tr>
105 <td>Status. For requests that got internally redirected, this is
106 the status of the *original* request --- %...>s for the last.</td></tr>
109 <td>Time, in common log format time format (standard english format)</td></tr>
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>
116 <td>The time taken to serve the request, in seconds.</td></tr>
119 <td>Remote user (from auth; may be bogus if return status (%s) is 401)</td></tr>
122 <td>The URL path requested, not including any query string.</td></tr>
125 <td>The canonical ServerName of the server serving the request.</td></tr>
128 <td>The server name according to the UseCanonicalName setting.</td></tr>
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.
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>
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>
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
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>
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>
169 <p>Some commonly used log format strings are:</p>
172 <dt>Common Log Format (CLF)</dt>
174 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
176 <dt>Common Log Format with Virtual Host</dt>
178 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
180 <dt>NCSA extended/combined log format</dt>
182 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
183 \"%{User-agent}i\""</code></dd>
185 <dt>Referer log format</dt>
187 <dd><code>"%{Referer}i -> %U"</code></dd>
189 <dt>Agent (Browser) log format</dt>
191 <dd><code>"%{User-agent}i"</code></dd>
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>
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>
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>
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>
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>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\" %>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.
307 <p>This directive specifies the format of the access log
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
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>
338 <div class="example"><p><code>LogFormat "%v %h %l %u %t \"%r\" %>s %b"
339 vhost_common</code></p></div>
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>
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>
360 <div class="example"><p><code>
361 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
362 TransferLog logs/access_log
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>