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>
143 <p>The "..." can be nothing at all (<em>e.g.</em>, <code>"%h %u
144 %r %s %b"</code>), or it can indicate conditions for inclusion
145 of the item (which will cause it to be replaced with "-" if the
146 condition is not met). The forms of condition are a list of
147 HTTP status codes, which may or may not be preceded by "!".
148 Thus, "%400,501{User-agent}i" logs User-agent: on 400 errors
149 and 501 errors (Bad Request, Not Implemented) only;
150 "%!200,304,302{Referer}i" logs Referer: on all requests which
151 did <strong>not</strong> return some sort of normal status.</p>
153 <p>Note that there is no escaping performed on the strings from
154 %...r, %...i and %...o. This is mainly to comply with the
155 requirements of the Common Log Format. This implies that
156 clients can insert control characters into the log, so care
157 should be taken when dealing with raw log files.</p>
159 <p>Some commonly used log format strings are:</p>
162 <dt>Common Log Format (CLF)</dt>
164 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
166 <dt>Common Log Format with Virtual Host</dt>
168 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
170 <dt>NCSA extended/combined log format</dt>
172 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
173 \"%{User-agent}i\""</code></dd>
175 <dt>Referer log format</dt>
177 <dd><code>"%{Referer}i -> %U"</code></dd>
179 <dt>Agent (Browser) log format</dt>
181 <dd><code>"%{User-agent}i"</code></dd>
184 <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
185 request are used for <code>%v</code> and <code>%p</code>
186 respectively. This happens regardless of the <a href="core.html#usecanonicalname">UseCanonicalName</a> setting
187 because otherwise log analysis programs would have to duplicate
188 the entire vhost matching algorithm in order to decide what
189 host really served the request.</p>
190 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2>Security Considerations</h2>
194 <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
195 document for details on why your security could be compromised
196 if the directory where logfiles are stored is writable by
197 anyone other than the user that starts the server.</p>
199 </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:
200 </a></th><td>Sets filename for the logging of cookies</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
201 </a></th><td>CookieLog <em>filename</em></td></tr><tr><th><a href="directive-dict.html#Context">Context:
202 </a></th><td>server config, virtual
203 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
204 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
205 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
206 </a></th><td>Only available in Apache 1.2 and above</td></tr></table>
208 <p>The <code class="directive">CookieLog</code> directive sets the
209 filename for logging of cookies. The filename is relative to the
210 <code class="directive"><a href="../mod/core.html#serverroot">serverroot</a></code>. This directive is
211 included only for compatibility with <code class="module"><a href="../mod/mod_cookies.html">mod_cookies</a></code>,
212 and is deprecated.</p>
213 </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:
214 </a></th><td>Sets filename and format of log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
215 </a></th><td>CustomLog
216 <em>file</em>|<em>pipe</em> <em>format</em>|<em>nickname</em>
217 [env=[!]<em>environment-variable</em>]</td></tr><tr><th><a href="directive-dict.html#Context">Context:
218 </a></th><td>server config, virtual
219 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
220 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
221 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
222 </a></th><td>Nickname only available in Apache 1.3 or later.
223 Conditional logging available in 1.3.5 or later.</td></tr></table>
224 <p>The <code class="directive">CustomLog</code> directive is used to
225 log requests to the server. A log format is specified, and the
226 logging can optionally be made conditional on request
227 characteristics using environment variables.</p>
229 <p>The first argument, which specifies the location to which
230 the logs will be written, can take on one of the following two
234 <dt><em>file</em></dt>
236 <dd>A filename, relative to the <a href="core.html#serverroot">ServerRoot</a>.</dd>
238 <dt><em>pipe</em></dt>
240 <dd>The pipe character "<code>|</code>", followed by the path
241 to a program to receive the log information on its standard
242 input. <strong>Security:</strong> if a program is used, then
243 it will be run under the user who started httpd. This will be
244 root if the server was started by root; be sure that the
245 program is secure.</dd>
248 <p>The second argument specifies what will be written to the
249 log file. It can specify either a <em>nickname</em> defined by
250 a previous <a href="#logformat">LogFormat</a> directive, or it
251 can be an explicit <em>format</em> string as described in the
252 <a href="#formats">log formats</a> section.</p>
254 <p>For example, the following two sets of directives have
255 exactly the same effect:</p>
257 <div class="example"><p><code>
258 # CustomLog with format nickname<br />
259 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
260 CustomLog logs/access_log common<br />
262 # CustomLog with explicit format string<br />
263 CustomLog logs/access_log "%h %l %u %t \"%r\" %>s %b"<br />
266 <p>The third argument is optional and allows the decision on
267 whether or not to log a particular request to be based on the
268 presence or absence of a particular variable in the server
269 environment. If the specified <a href="../env.html">environment
270 variable</a> is set for the request (or is not set, in the case
271 of a '<code>env=!<em>name</em></code>' clause), then the
272 request will be logged.</p>
274 <p>Environment variables can be set on a <em>per</em>-request
275 basis using the <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
276 and/or <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> modules. For
277 example, if you want to record requests for all GIF
278 images on your server in a separate logfile but not in your main
279 log, you can use:</p>
281 <div class="example"><p><code>
282 SetEnvIf Request_URI \.gif$ gif-image<br />
283 CustomLog gif-requests.log common env=gif-image<br />
284 CustomLog nongif-requests.log common env=!gif-image
286 </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:
287 </a></th><td>Describes a format for use in a log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
288 </a></th><td>LogFormat
289 <em>format</em>|<em>nickname</em> [<em>nickname</em>]</td></tr><tr><th><a href="directive-dict.html#Default">Default:
290 </a></th><td><code>LogFormat "%h %l %u %t \"%r\" %>s %b"</code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
291 </a></th><td>server config, virtual
292 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
293 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
294 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
295 </a></th><td>Nickname only available in Apache 1.3 or later.
297 <p>This directive specifies the format of the access log
300 <p>The <code class="directive">LogFormat</code> directive can take one of two
301 forms. In the first form, where only one argument is specified,
302 this directive sets the log format which will be used by logs
303 specified in subsequent <code class="directive">TransferLog</code>
304 directives. The single argument can specify an explicit
305 <em>format</em> as discussed in <a href="#formats">custom log
306 formats</a> section above. Alternatively, it can use a
307 <em>nickname</em> to refer to a log format defined in a
308 previous <code class="directive">LogFormat</code> directive as described
311 <p>The second form of the <code class="directive">LogFormat</code>
312 directive associates an explicit <em>format</em> with a
313 <em>nickname</em>. This <em>nickname</em> can then be used in
314 subsequent <code class="directive">LogFormat</code> or
315 <code class="directive">CustomLog</code> directives rather than
316 repeating the entire format string. A
317 <code class="directive">LogFormat</code>
318 directive that defines a nickname <strong>does nothing
319 else</strong> -- that is, it <em>only</em> defines the
320 nickname, it doesn't actually apply the format and make it the
321 default. Therefore, it will not affect subsequent
322 <code class="directive">TransferLog</code> directives. In addition,
323 <code class="directive">LogFormat</code> cannot use one nickname
324 to define another nickname.</p>
328 <div class="example"><p><code>LogFormat "%v %h %l %u %t \"%r\" %>s %b"
329 vhost_common</code></p></div>
331 </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:
332 </a></th><td>Specifly location of a log file</td></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
333 </a></th><td>TransferLog <em>file</em>|<em>pipe</em></td></tr><tr><th><a href="directive-dict.html#Context">Context:
334 </a></th><td>server config, virtual
335 host</td></tr><tr><th><a href="directive-dict.html#Status">Status:
336 </a></th><td>Base</td></tr><tr><th><a href="directive-dict.html#Module">Module:
337 </a></th><td>mod_log_config</td></tr><tr><th><a href="directive-dict.html#Compatibility">Compatibility:
338 </a></th><td /></tr></table>
340 <p>This directive has exactly the same arguments and effect as
341 the <code class="directive">CustomLog</code> directive, with the
342 exception that it does not allow the log format to be specified
343 explicitly or for conditional logging of requests. Instead, the
344 log format is determined by the most recently specified
345 <code class="directive">LogFormat</code> directive (which
346 does not define a nickname). Common Log Format is used if no
347 other format has been specified.</p>
350 <div class="example"><p><code>
351 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""<br />
352 TransferLog logs/access_log
355 </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>