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 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 This file is generated from xml source: DO NOT EDIT
8 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 <title>mod_log_config - Apache HTTP Server Version 2.5</title>
11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
14 <script src="../style/scripts/prettify.min.js" type="text/javascript">
17 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
19 <div id="page-header">
20 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
21 <p class="apache">Apache HTTP Server Version 2.5</p>
22 <img alt="" src="../images/feather.gif" /></div>
23 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
25 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.5</a> > <a href="./">Modules</a></div>
26 <div id="page-content">
27 <div id="preamble"><h1>Apache Module mod_log_config</h1>
29 <p><span>Available Languages: </span><a href="../en/mod/mod_log_config.html" title="English"> en </a> |
30 <a href="../ja/mod/mod_log_config.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
31 <a href="../ko/mod/mod_log_config.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
32 <a href="../tr/mod/mod_log_config.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
34 <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>
35 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
36 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>log_config_module</td></tr>
37 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_log_config.c</td></tr></table>
40 <p>This module provides for flexible logging of client
41 requests. Logs are written in a customizable format, and may be
42 written directly to a file, or to an external program.
43 Conditional logging is provided so that individual requests may
44 be included or excluded from the logs based on characteristics
47 <p>Three directives are provided by this module:
48 <code class="directive"><a href="#transferlog">TransferLog</a></code> to create
49 a log file, <code class="directive"><a href="#logformat">LogFormat</a></code>
50 to set a custom format, and <code class="directive"><a href="#customlog">CustomLog</a></code> to define a log file and format in one
51 step. The <code class="directive">TransferLog</code> and <code class="directive">CustomLog</code> directives can be used multiple times in each
52 server to cause each request to be logged to multiple files.</p>
54 <div id="quickview"><h3>Topics</h3>
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 class="directives">Directives</h3>
60 <li><img alt="" src="../images/down.gif" /> <a href="#bufferedlogs">BufferedLogs</a></li>
61 <li><img alt="" src="../images/down.gif" /> <a href="#customlog">CustomLog</a></li>
62 <li><img alt="" src="../images/down.gif" /> <a href="#globallog">GlobalLog</a></li>
63 <li><img alt="" src="../images/down.gif" /> <a href="#logformat">LogFormat</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#transferlog">TransferLog</a></li>
68 <li><a href="../logs.html">Apache Log Files</a></li>
69 </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
70 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
72 <h2><a name="formats" id="formats">Custom Log Formats</a></h2>
74 <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
75 used to log each request to the log file. It can contain literal
76 characters copied into the log files and the C-style control
77 characters "\n" and "\t" to represent new-lines and tabs.
78 Literal quotes and backslashes should be escaped with
81 <p>The characteristics of the request itself are logged by
82 placing "<code>%</code>" directives in the format string, which are
83 replaced in the log file by the values as follows:</p>
85 <table class="bordered"><tr class="header"><th>Format String</th>
86 <th>Description</th></tr>
87 <tr><td><code>%%</code></td>
88 <td>The percent sign.</td></tr>
89 <tr class="odd"><td><code>%a</code></td>
90 <td>Client IP address of the request (see the
91 <code class="module"><a href="../mod/mod_remoteip.html">mod_remoteip</a></code> module).</td></tr>
92 <tr><td><code>%{c}a</code></td>
93 <td>Underlying peer IP address of the connection (see the
94 <code class="module"><a href="../mod/mod_remoteip.html">mod_remoteip</a></code> module).</td></tr>
95 <tr class="odd"><td><code>%A</code></td>
96 <td>Local IP-address.</td></tr>
97 <tr><td><code>%B</code></td>
98 <td>Size of response in bytes, excluding HTTP headers.</td></tr>
99 <tr class="odd"><td><code>%b</code></td>
100 <td>Size of response in bytes, excluding HTTP headers. In CLF format, <em>i.e.</em>
101 a '<code>-</code>' rather than a 0 when no bytes are sent.</td></tr>
102 <tr><td><code>%{<var>VARNAME</var>}C</code></td>
103 <td>The contents of cookie <var>VARNAME</var> in the request sent
104 to the server. Only version 0 cookies are fully supported.</td></tr>
105 <tr class="odd"><td><code>%D</code></td>
106 <td>The time taken to serve the request, in microseconds.</td></tr>
107 <tr><td><code>%{<var>VARNAME</var>}e</code></td>
108 <td>The contents of the environment variable
109 <var>VARNAME</var>.</td></tr>
110 <tr class="odd"><td><code>%f</code></td>
111 <td>Filename.</td></tr>
112 <tr><td><code>%h</code></td>
113 <td>Remote hostname. Will log the IP address if <code class="directive"><a href="../mod/core.html#hostnamelookups">HostnameLookups</a></code> is set to
114 <code>Off</code>, which is the default. If it logs the hostname
115 for only a few hosts, you probably have access control
116 directives mentioning them by name. See <a href="mod_authz_host.html#reqhost">the Require host
117 documentation</a>.</td></tr>
118 <tr class="odd"><td><code>%H</code></td>
119 <td>The request protocol.</td></tr>
120 <tr><td><code>%{<var>VARNAME</var>}i</code></td>
121 <td>The contents of <code><var>VARNAME</var>:</code> header line(s)
122 in the request sent to the server. Changes made by other
123 modules (e.g. <code class="module"><a href="../mod/mod_headers.html">mod_headers</a></code>) affect this. If you're
124 interested in what the request header was prior to when most
125 modules would have modified it, use <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
126 to copy the header into an internal environment variable and log
127 that value with the <code>%{<var>VARNAME</var>}e</code> described
130 <tr class="odd"><td><code>%k</code></td>
131 <td>Number of keepalive requests handled on this connection. Interesting if
132 <code class="directive"><a href="../mod/core.html#keepalive">KeepAlive</a></code> is being used, so that,
133 for example, a '1' means the first keepalive request after the initial
134 one, '2' the second, etc...;
135 otherwise this is always 0 (indicating the initial request).</td></tr>
136 <tr><td><code>%l</code></td>
137 <td>Remote logname (from identd, if supplied). This will return a
138 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
139 <code>On</code>.</td></tr>
140 <tr class="odd"><td><code>%L</code></td>
141 <td>The request log ID from the error log (or '-' if nothing has been
142 logged to the error log for this request). Look for the
143 matching error log line to see what request caused what error.</td></tr>
144 <tr><td><code>%m</code></td>
145 <td>The request method.</td></tr>
146 <tr class="odd"><td><code>%{<var>VARNAME</var>}n</code></td>
147 <td>The contents of note <var>VARNAME</var> from another
149 <tr><td><code>%{<var>VARNAME</var>}o</code></td>
150 <td>The contents of <code><var>VARNAME</var>:</code> header line(s)
151 in the reply.</td></tr>
152 <tr class="odd"><td><code>%p</code></td>
153 <td>The canonical port of the server serving the request.</td></tr>
154 <tr><td><code>%{<var>format</var>}p</code></td>
155 <td>The canonical port of the server serving the request, or the
156 server's actual port, or the client's actual port. Valid formats
157 are <code>canonical</code>, <code>local</code>, or <code>remote</code>.
159 <tr class="odd"><td><code>%P</code></td>
160 <td>The process ID of the child that serviced the request.</td></tr>
161 <tr><td><code>%{<var>format</var>}P</code></td>
162 <td>The process ID or thread ID of the child that serviced the
163 request. Valid formats are <code>pid</code>, <code>tid</code>,
164 and <code>hextid</code>. <code>hextid</code> requires APR 1.2.0 or
167 <tr class="odd"><td><code>%q</code></td>
168 <td>The query string (prepended with a <code>?</code> if a query
169 string exists, otherwise an empty string).</td></tr>
170 <tr><td><code>%r</code></td>
171 <td>First line of request.</td></tr>
172 <tr class="odd"><td><code>%R</code></td>
173 <td>The handler generating the response (if any).</td></tr>
174 <tr><td><code>%s</code></td>
175 <td>Status. For requests that have been internally redirected, this is
176 the status of the <em>original</em> request. Use <code>%>s</code>
177 for the final status.</td></tr>
178 <tr class="odd"><td><code>%t</code></td>
179 <td>Time the request was received, in the format <code>[18/Sep/2011:19:18:28 -0400]</code>.
180 The last number indicates the timezone offset from GMT</td></tr>
181 <tr><td><code>%{<var>format</var>}t</code></td>
182 <td>The time, in the form given by format, which should be in
183 an extended <code>strftime(3)</code> format (potentially localized).
184 If the format starts with <code>begin:</code> (default) the time is taken
185 at the beginning of the request processing. If it starts with
186 <code>end:</code> it is the time when the log entry gets written,
187 close to the end of the request processing. In addition to the formats
188 supported by <code>strftime(3)</code>, the following format tokens are
191 <tr><td><code>sec</code></td><td>number of seconds since the Epoch</td></tr>
192 <tr><td><code>msec</code></td><td>number of milliseconds since the Epoch</td></tr>
193 <tr><td><code>usec</code></td><td>number of microseconds since the Epoch</td></tr>
194 <tr><td><code>msec_frac</code></td><td>millisecond fraction</td></tr>
195 <tr><td><code>usec_frac</code></td><td>microsecond fraction</td></tr>
197 These tokens can not be combined with each other or <code>strftime(3)</code>
198 formatting in the same format string. You can use multiple
199 <code>%{<var>format</var>}t</code> tokens instead.
201 <tr class="odd"><td><code>%T</code></td>
202 <td>The time taken to serve the request, in seconds.</td></tr>
203 <tr><td><code>%{<var>UNIT</var>}T</code></td>
204 <td>The time taken to serve the request, in a time unit given by
205 <code>UNIT</code>. Valid units are <code>ms</code> for milliseconds,
206 <code>us</code> for microseconds, and <code>s</code> for seconds.
207 Using <code>s</code> gives the same result as <code>%T</code>
208 without any format; using <code>us</code> gives the same result
209 as <code>%D</code>. Combining <code>%T</code> with a unit is
210 available in 2.4.13 and later.</td></tr>
211 <tr class="odd"><td><code>%u</code></td>
212 <td>Remote user if the request was authenticated. May be bogus if return status
213 (<code>%s</code>) is 401 (unauthorized).</td></tr>
214 <tr><td><code>%U</code></td>
215 <td>The URL path requested, not including any query string.</td></tr>
216 <tr class="odd"><td><code>%v</code></td>
217 <td>The canonical <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code>
218 of the server serving the request.</td></tr>
219 <tr><td><code>%V</code></td>
220 <td>The server name according to the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> setting.</td></tr>
221 <tr class="odd"><td><code>%X</code></td>
222 <td>Connection status when response is completed:
226 <tr><td><code>X</code> =</td>
227 <td>Connection aborted before the response completed.</td></tr>
228 <tr><td><code>+</code> =</td>
229 <td>Connection may be kept alive after the response is
231 <tr><td><code>-</code> = </td>
232 <td>Connection will be closed after the response is
237 <tr><td><code>%I</code></td>
238 <td>Bytes received, including request and headers. Cannot be zero.
239 You need to enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
240 <tr class="odd"><td><code>%O</code></td>
241 <td>Bytes sent, including headers. May be zero in rare cases
242 such as when a request is aborted before a response is sent.
243 You need to enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
244 <tr><td><code>%S</code></td>
245 <td>Bytes transferred (received and sent), including request and headers,
246 cannot be zero. This is the combination of %I and %O. You need to
247 enable <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> to use this.</td></tr>
248 <tr class="odd"><td><code>%{<var>VARNAME</var>}^ti</code></td>
249 <td>The contents of <code><var>VARNAME</var>:</code> trailer line(s)
250 in the request sent to the server. </td></tr>
251 <tr><td><code>%{<var>VARNAME</var>}^to</code></td>
252 <td>The contents of <code><var>VARNAME</var>:</code> trailer line(s)
253 in the response sent from the server. </td></tr>
256 <h3><a name="modifiers" id="modifiers">Modifiers</a></h3>
258 <p>Particular items can be restricted to print only for
259 responses with specific HTTP status codes by placing a
260 comma-separated list of status codes immediately following the
261 "%". The status code list may be preceded by a "<code>!</code>" to
262 indicate negation.</p>
264 <table class="bordered"><tr class="header"><th>Format String</th>
265 <th>Meaning</th></tr>
267 <td><code>%400,501{User-agent}i</code></td>
268 <td>Logs <code>User-agent</code> on 400 errors and 501 errors only. For
269 other status codes, the literal string <code>"-"</code> will be
271 <tr class="odd"><td><code>%!200,304,302{Referer}i</code></td>
272 <td>Logs <code>Referer</code> on all requests that do
273 <em>not</em> return one of the three specified codes,
274 "<code>-</code>" otherwise.
278 <p>The modifiers "<" and ">" can be used for requests that
279 have been internally redirected to choose whether the original
280 or final (respectively) request should be consulted. By
281 default, the <code>%</code> directives <code>%s, %U, %T,
282 %D,</code> and <code>%r</code> look at the original request
283 while all others look at the final request. So for example,
284 <code>%>s</code> can be used to record the final status of
285 the request and <code>%<u</code> can be used to record the
286 original authenticated user on a request that is internally
287 redirected to an unauthenticated resource.</p>
291 <h3><a name="format-notes" id="format-notes">Format Notes</a></h3>
293 <p>For security reasons, starting with version 2.0.46,
294 non-printable and other special characters in <code>%r</code>,
295 <code>%i</code> and <code>%o</code> are escaped using
296 <code>\x<var>hh</var></code> sequences, where <var>hh</var>
297 stands for the hexadecimal representation of the raw
298 byte. Exceptions from this rule are <code>"</code> and
299 <code>\</code>, which are escaped by prepending a backslash, and
300 all whitespace characters, which are written in their C-style
301 notation (<code>\n</code>, <code>\t</code>, etc). In versions
302 prior to 2.0.46, no escaping was performed on these strings so
303 you had to be quite careful when dealing with raw log files.</p>
305 <p>Since httpd 2.0, unlike 1.3, the <code>%b</code> and
306 <code>%B</code> format strings do not represent the number of
307 bytes sent to the client, but simply the size in bytes of the
308 HTTP response (which will differ, for instance, if the
309 connection is aborted, or if SSL is used). The <code>%O</code>
310 format provided by <code class="module"><a href="../mod/mod_logio.html">mod_logio</a></code> will log the
311 actual number of bytes sent over the network.</p>
314 <p>Note: <code class="module"><a href="../mod/mod_cache.html">mod_cache</a></code> is implemented as a
315 quick-handler and not as a standard handler. Therefore, the
316 <code>%R</code> format string will not return any handler
317 information when content caching is involved.</p>
321 <p>Note: The '^' character at the start of three-character formats
322 has no significance, but it must be the first character of any newly
323 added three-character format to avoid potential conflicts with log
324 formats that use literals adjacent to a format specifier, such as
330 <h3><a name="examples" id="examples">Examples</a></h3>
332 <p>Some commonly used log format strings are:</p>
335 <dt>Common Log Format (CLF)</dt>
336 <dd><code>"%h %l %u %t \"%r\" %>s %b"</code></dd>
338 <dt>Common Log Format with Virtual Host</dt>
339 <dd><code>"%v %h %l %u %t \"%r\" %>s %b"</code></dd>
341 <dt>NCSA extended/combined log format</dt>
342 <dd><code>"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
343 \"%{User-agent}i\""</code></dd>
345 <dt>Referer log format</dt>
346 <dd><code>"%{Referer}i -> %U"</code></dd>
348 <dt>Agent (Browser) log format</dt>
349 <dd><code>"%{User-agent}i"</code></dd>
352 <p>You can use the <code>%{format}t</code> directive multiple
353 times to build up a time format using the extended format tokens
354 like <code>msec_frac</code>:</p>
356 <dt>Timestamp including milliseconds</dt>
357 <dd><code>"%{%d/%b/%Y %T}t.%{msec_frac}t %{%z}t"</code></dd>
362 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
363 <div class="section">
364 <h2><a name="security" id="security">Security Considerations</a></h2>
365 <p>See the <a href="../misc/security_tips.html#serverroot">security tips</a>
366 document for details on why your security could be compromised
367 if the directory where logfiles are stored is writable by
368 anyone other than the user that starts the server.</p>
370 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
371 <div class="directive-section"><h2><a name="BufferedLogs" id="BufferedLogs">BufferedLogs</a> <a name="bufferedlogs" id="bufferedlogs">Directive</a></h2>
372 <table class="directive">
373 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Buffer log entries in memory before writing to disk</td></tr>
374 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BufferedLogs On|Off</code></td></tr>
375 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>BufferedLogs Off</code></td></tr>
376 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
377 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
378 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
380 <p>The <code class="directive">BufferedLogs</code> directive causes
381 <code class="module"><a href="../mod/mod_log_config.html">mod_log_config</a></code> to store several log entries in
382 memory and write them together to disk, rather than writing them
383 after each request. On some systems, this may result in more
384 efficient disk access and hence higher performance. It may be
385 set only once for the entire server; it cannot be configured
386 per virtual-host.</p>
388 <div class="note">This directive should be used with caution as a crash might
389 cause loss of logging data.</div>
392 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
393 <div class="directive-section"><h2><a name="CustomLog" id="CustomLog">CustomLog</a> <a name="customlog" id="customlog">Directive</a></h2>
394 <table class="directive">
395 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename and format of log file</td></tr>
396 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>CustomLog <var>file</var>|<var>pipe</var>|<var>provider</var>
397 <var>format</var>|<var>nickname</var>
398 [env=[!]<var>environment-variable</var>|
399 expr=<var>expression</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>The <code class="directive">CustomLog</code> directive is used to
405 log requests to the server. A log format is specified, and the
406 logging can optionally be made conditional on request
407 characteristics using environment variables.</p>
409 <p>The first argument, which specifies the location to which
410 the logs will be written, can take one of the following two
414 <dt><var>file</var></dt>
415 <dd>A filename, relative to the <code class="directive"><a href="../mod/core.html#serverroot">ServerRoot</a></code>.</dd>
417 <dt><var>pipe</var></dt>
418 <dd>The pipe character "<code>|</code>", followed by the path
419 to a program to receive the log information on its standard
420 input. See the notes on <a href="../logs.html#piped">piped logs</a>
421 for more information.
423 <div class="warning"><h3>Security:</h3>
424 <p>If a program is used, then it will be run as the user who
425 started <code class="program"><a href="../programs/httpd.html">httpd</a></code>. This will be root if the server was
426 started by root; be sure that the program is secure.</p>
428 <div class="warning"><h3>Note</h3>
429 <p>When entering a file path on non-Unix platforms, care should be taken
430 to make sure that only forward slashed are used even though the platform
431 may allow the use of back slashes. In general it is a good idea to always
432 use forward slashes throughout the configuration files.</p>
434 <dt><var>provider</var></dt>
435 <dd>Modules implementing ErrorLog providers can also be used as a target
436 for CustomLog messages. To use ErrorLog provider as a target,
437 "provider:argument" syntax must be used. You can for example use
438 <code class="module"><a href="../mod/mod_journald.html">mod_journald</a></code> or <code class="module"><a href="../mod/mod_syslog.html">mod_syslog</a></code>
440 <pre class="prettyprint lang-config"># CustomLog logging to journald
441 CustomLog "journald" "%h %l %u %t \"%r\" %>s %b"
443 # CustomLog logging to syslog with "user" facility
444 CustomLog "syslog:user" "%h %l %u %t \"%r\" %>s %b"</pre>
449 <p>The second argument specifies what will be written to the
450 log file. It can specify either a <var>nickname</var> defined by
451 a previous <code class="directive"><a href="#logformat">LogFormat</a></code>
452 directive, or it can be an explicit <var>format</var> string as
453 described in the <a href="#formats">log formats</a> section.</p>
455 <p>For example, the following two sets of directives have
456 exactly the same effect:</p>
458 <pre class="prettyprint lang-config"># CustomLog with format nickname
459 LogFormat "%h %l %u %t \"%r\" %>s %b" common
460 CustomLog "logs/access_log" common
462 # CustomLog with explicit format string
463 CustomLog "logs/access_log" "%h %l %u %t \"%r\" %>s %b"</pre>
466 <p>The third argument is optional and controls whether or
467 not to log a particular request. The condition can be the
468 presence or absence (in the case of a '<code>env=!<var>name</var></code>'
469 clause) of a particular variable in the server
470 <a href="../env.html">environment</a>. Alternatively, the condition
471 can be expressed as arbitrary boolean <a href="../expr.html">expression</a>. If the condition is not satisfied, the request
472 will not be logged. References to HTTP headers in the expression
473 will not cause the header names to be added to the Vary header.</p>
475 <p>Environment variables can be set on a per-request
476 basis using the <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code>
477 and/or <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> modules. For
478 example, if you want to record requests for all GIF
479 images on your server in a separate logfile but not in your main
480 log, you can use:</p>
482 <pre class="prettyprint lang-config">SetEnvIf Request_URI \.gif$ gif-image
483 CustomLog "gif-requests.log" common env=gif-image
484 CustomLog "nongif-requests.log" common env=!gif-image</pre>
487 <p>Or, to reproduce the behavior of the old RefererIgnore
488 directive, you might use the following:</p>
490 <pre class="prettyprint lang-config">SetEnvIf Referer example\.com localreferer
491 CustomLog "referer.log" referer env=!localreferer</pre>
495 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
496 <div class="directive-section"><h2><a name="GlobalLog" id="GlobalLog">GlobalLog</a> <a name="globallog" id="globallog">Directive</a></h2>
497 <table class="directive">
498 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets filename and format of log file</td></tr>
499 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>GlobalLog <var>file</var>|<var>pipe</var>|<var>provider</var>
500 <var>format</var>|<var>nickname</var>
501 [env=[!]<var>environment-variable</var>|
502 expr=<var>expression</var>]</code></td></tr>
503 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
504 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
505 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
506 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Available in Apache HTTP Server 2.4.19 and later</td></tr>
509 <p>The <code class="directive">GlobalLog</code> directive defines a log shared
510 by the main server configuration and all defined virtual hosts.</p>
512 <p>The <code class="directive">GlobalLog</code> directive is identical to
513 the <code class="directive">CustomLog</code> directive, apart from the following
516 <li><code class="directive">GlobalLog</code> is not valid in virtual host
518 <li><code class="directive">GlobalLog</code> is used by virtual hosts that
519 define their own <code class="directive">CustomLog</code>, unlike a
520 globally specified <code class="directive">CustomLog</code>.</li>
524 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
525 <div class="directive-section"><h2><a name="LogFormat" id="LogFormat">LogFormat</a> <a name="logformat" id="logformat">Directive</a></h2>
526 <table class="directive">
527 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Describes a format for use in a log file</td></tr>
528 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LogFormat <var>format</var>|<var>nickname</var>
529 [<var>nickname</var>]</code></td></tr>
530 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LogFormat "%h %l %u %t \"%r\" %>s %b"</code></td></tr>
531 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
532 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
533 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
535 <p>This directive specifies the format of the access log
538 <p>The <code class="directive">LogFormat</code> directive can take one of two
539 forms. In the first form, where only one argument is specified,
540 this directive sets the log format which will be used by logs
541 specified in subsequent <code class="directive">TransferLog</code>
542 directives. The single argument can specify an explicit
543 <var>format</var> as discussed in the <a href="#formats">custom log
544 formats</a> section above. Alternatively, it can use a
545 <var>nickname</var> to refer to a log format defined in a
546 previous <code class="directive">LogFormat</code> directive as described
549 <p>The second form of the <code class="directive">LogFormat</code>
550 directive associates an explicit <var>format</var> with a
551 <var>nickname</var>. This <var>nickname</var> can then be used in
552 subsequent <code class="directive">LogFormat</code> or
553 <code class="directive"><a href="#customlog">CustomLog</a></code> directives
554 rather than repeating the entire format string. A
555 <code class="directive">LogFormat</code> directive that defines a nickname
556 <strong>does nothing else</strong> -- that is, it <em>only</em>
557 defines the nickname, it doesn't actually apply the format and make
558 it the default. Therefore, it will not affect subsequent
559 <code class="directive"><a href="#transferlog">TransferLog</a></code> directives.
560 In addition, <code class="directive">LogFormat</code> cannot use one nickname
561 to define another nickname. Note that the nickname should not contain
562 percent signs (<code>%</code>).</p>
564 <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common</pre>
569 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
570 <div class="directive-section"><h2><a name="TransferLog" id="TransferLog">TransferLog</a> <a name="transferlog" id="transferlog">Directive</a></h2>
571 <table class="directive">
572 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify location of a log file</td></tr>
573 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>TransferLog <var>file</var>|<var>pipe</var></code></td></tr>
574 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
575 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
576 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_log_config</td></tr>
578 <p>This directive has exactly the same arguments and effect as
579 the <code class="directive"><a href="#customlog">CustomLog</a></code>
580 directive, with the exception that it does not allow the log format
581 to be specified explicitly or for conditional logging of requests.
582 Instead, the log format is determined by the most recently specified
583 <code class="directive"><a href="#logformat">LogFormat</a></code> directive
584 which does not define a nickname. Common Log Format is used if no
585 other format has been specified.</p>
587 <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
588 TransferLog "logs/access_log"</pre>
593 <div class="bottomlang">
594 <p><span>Available Languages: </span><a href="../en/mod/mod_log_config.html" title="English"> en </a> |
595 <a href="../ja/mod/mod_log_config.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
596 <a href="../ko/mod/mod_log_config.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
597 <a href="../tr/mod/mod_log_config.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
598 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
599 <script type="text/javascript"><!--//--><![CDATA[//><!--
600 var comments_shortname = 'httpd';
601 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_log_config.html';
603 if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
604 d.write('<div id="comments_thread"><\/div>');
605 var s = d.createElement('script');
606 s.type = 'text/javascript';
608 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
609 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
612 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
614 })(window, document);
615 //--><!]]></script></div><div id="footer">
616 <p class="apache">Copyright 2016 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>
617 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
618 if (typeof(prettyPrint) !== 'undefined') {