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