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