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
8 <title>Log Files - 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" />
12 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.3</p>
16 <img alt="" src="./images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="<-" alt="<-" src="./images/left.gif" /></a></div>
19 <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.3</a></div><div id="page-content"><div id="preamble"><h1>Log Files</h1>
21 <p><span>Available Languages: </span><a href="./en/logs.html" title="English"> en </a> |
22 <a href="./fr/logs.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
23 <a href="./ja/logs.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
24 <a href="./ko/logs.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
25 <a href="./tr/logs.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
28 <p>In order to effectively manage a web server, it is necessary
29 to get feedback about the activity and performance of the
30 server as well as any problems that may be occurring. The Apache HTTP Server
31 provides very comprehensive and flexible logging
32 capabilities. This document describes how to configure its
33 logging capabilities, and how to understand what the logs
36 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#overview">Overview</a></li>
37 <li><img alt="" src="./images/down.gif" /> <a href="#security">Security Warning</a></li>
38 <li><img alt="" src="./images/down.gif" /> <a href="#errorlog">Error Log</a></li>
39 <li><img alt="" src="./images/down.gif" /> <a href="#accesslog">Access Log</a></li>
40 <li><img alt="" src="./images/down.gif" /> <a href="#rotation">Log Rotation</a></li>
41 <li><img alt="" src="./images/down.gif" /> <a href="#piped">Piped Logs</a></li>
42 <li><img alt="" src="./images/down.gif" /> <a href="#virtualhost">Virtual Hosts</a></li>
43 <li><img alt="" src="./images/down.gif" /> <a href="#other">Other Log Files</a></li>
45 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
47 <h2><a name="overview" id="overview">Overview</a></h2>
50 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/mod_log_config.html">mod_log_config</a></code></li><li><code class="module"><a href="./mod/mod_log_forensic.html">mod_log_forensic</a></code></li><li><code class="module"><a href="./mod/mod_logio.html">mod_logio</a></code></li><li><code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code></li><li><code class="module"><a href="./mod/mod_cgi.html">mod_cgi</a></code></li></ul></td><td /></tr></table>
53 The Apache HTTP Server provides a variety of different mechanisms for
54 logging everything that happens on your server, from the initial
55 request, through the URL mapping process, to the final resolution of
56 the connection, including any errors that may have occurred in the
57 process. In addition to this, third-party modules may provide logging
58 capabilities, or inject entries into the existing log files, and
59 applications such as CGI programs, or PHP scripts, or other handlers,
60 may send messages to the server error log.
64 In this document we discuss the logging modules that are a standard
65 part of the http server.
68 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
70 <h2><a name="security" id="security">Security Warning</a></h2>
73 <p>Anyone who can write to the directory where Apache httpd is
74 writing a log file can almost certainly gain access to the uid
75 that the server is started as, which is normally root. Do
76 <em>NOT</em> give people write access to the directory the logs
77 are stored in without being aware of the consequences; see the
78 <a href="misc/security_tips.html">security tips</a> document
81 <p>In addition, log files may contain information supplied
82 directly by the client, without escaping. Therefore, it is
83 possible for malicious clients to insert control-characters in
84 the log files, so care must be taken in dealing with raw
86 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
88 <h2><a name="errorlog" id="errorlog">Error Log</a></h2>
91 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/core.html">core</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/core.html#errorlog">ErrorLog</a></code></li><li><code class="directive"><a href="./mod/core.html#loglevel">LogLevel</a></code></li></ul></td></tr></table>
93 <p>The server error log, whose name and location is set by the
94 <code class="directive"><a href="./mod/core.html#errorlog">ErrorLog</a></code> directive, is the
95 most important log file. This is the place where Apache httpd
96 will send diagnostic information and record any errors that it
97 encounters in processing requests. It is the first place to
98 look when a problem occurs with starting the server or with the
99 operation of the server, since it will often contain details of
100 what went wrong and how to fix it.</p>
102 <p>The error log is usually written to a file (typically
103 <code>error_log</code> on Unix systems and
104 <code>error.log</code> on Windows and OS/2). On Unix systems it
105 is also possible to have the server send errors to
106 <code>syslog</code> or <a href="#piped">pipe them to a
109 <p>The format of the error log is relatively free-form and
110 descriptive. But there is certain information that is contained
111 in most error log entries. For example, here is a typical
114 <div class="example"><p><code>
115 [Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1]
116 client denied by server configuration:
117 /export/home/live/ap/htdocs/test
120 <p>The first item in the log entry is the date and time of the
121 message. The second item lists the severity of the error being
122 reported. The <code class="directive"><a href="./mod/core.html#loglevel">LogLevel</a></code>
123 directive is used to control the types of errors that are sent
124 to the error log by restricting the severity level. The third
125 item gives the IP address of the client that generated the
126 error. Beyond that is the message itself, which in this case
127 indicates that the server has been configured to deny the
128 client access. The server reports the file-system path (as
129 opposed to the web path) of the requested document.</p>
131 <p>A very wide variety of different messages can appear in the
132 error log. Most look similar to the example above. The error
133 log will also contain debugging output from CGI scripts. Any
134 information written to <code>stderr</code> by a CGI script will
135 be copied directly to the error log.</p>
137 <p>It is not possible to customize the error log by adding or
138 removing information. However, error log entries dealing with
139 particular requests have corresponding entries in the <a href="#accesslog">access log</a>. For example, the above example
140 entry corresponds to an access log entry with status code 403.
141 Since it is possible to customize the access log, you can
142 obtain more information about error conditions using that log
145 <p>During testing, it is often useful to continuously monitor
146 the error log for any problems. On Unix systems, you can
147 accomplish this using:</p>
149 <div class="example"><p><code>
152 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
153 <div class="section">
154 <h2><a name="accesslog" id="accesslog">Access Log</a></h2>
157 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/mod_log_config.html">mod_log_config</a></code></li><li><code class="module"><a href="./mod/mod_setenvif.html">mod_setenvif</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code></li><li><code class="directive"><a href="./mod/mod_log_config.html#logformat">LogFormat</a></code></li><li><code class="directive"><a href="./mod/mod_setenvif.html#setenvif">SetEnvIf</a></code></li></ul></td></tr></table>
159 <p>The server access log records all requests processed by the
160 server. The location and content of the access log are
161 controlled by the <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code>
162 directive. The <code class="directive"><a href="./mod/mod_log_config.html#logformat">LogFormat</a></code>
163 directive can be used to simplify the selection of
164 the contents of the logs. This section describes how to configure the server
165 to record information in the access log.</p>
167 <p>Of course, storing the information in the access log is only
168 the start of log management. The next step is to analyze this
169 information to produce useful statistics. Log analysis in
170 general is beyond the scope of this document, and not really
171 part of the job of the web server itself. For more information
172 about this topic, and for applications which perform log
173 analysis, check the <a href="http://dmoz.org/Computers/Software/Internet/Site_Management/Log_analysis/">
174 Open Directory</a> or <a href="http://dir.yahoo.com/Computers_and_Internet/Software/Internet/World_Wide_Web/Servers/Log_Analysis_Tools/">
177 <p>Various versions of Apache httpd have used other modules and
178 directives to control access logging, including
179 mod_log_referer, mod_log_agent, and the
180 <code>TransferLog</code> directive. The <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code> directive now subsumes
181 the functionality of all the older directives.</p>
183 <p>The format of the access log is highly configurable. The format
184 is specified using a format string that looks much like a C-style
185 printf(1) format string. Some examples are presented in the next
186 sections. For a complete list of the possible contents of the
187 format string, see the <code class="module"><a href="./mod/mod_log_config.html">mod_log_config</a></code> <a href="mod/mod_log_config.html#formats">format strings</a>.</p>
189 <h3><a name="common" id="common">Common Log Format</a></h3>
192 <p>A typical configuration for the access log might look as
195 <div class="example"><p><code>
196 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
197 CustomLog logs/access_log common
200 <p>This defines the <em>nickname</em> <code>common</code> and
201 associates it with a particular log format string. The format
202 string consists of percent directives, each of which tell the
203 server to log a particular piece of information. Literal
204 characters may also be placed in the format string and will be
205 copied directly into the log output. The quote character
206 (<code>"</code>) must be escaped by placing a backslash before
207 it to prevent it from being interpreted as the end of the
208 format string. The format string may also contain the special
209 control characters "<code>\n</code>" for new-line and
210 "<code>\t</code>" for tab.</p>
212 <p>The <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code>
213 directive sets up a new log file using the defined
214 <em>nickname</em>. The filename for the access log is relative to
215 the <code class="directive"><a href="./mod/core.html#serverroot">ServerRoot</a></code> unless it
216 begins with a slash.</p>
218 <p>The above configuration will write log entries in a format
219 known as the Common Log Format (CLF). This standard format can
220 be produced by many different web servers and read by many log
221 analysis programs. The log file entries produced in CLF will
222 look something like this:</p>
224 <div class="example"><p><code>
225 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET
226 /apache_pb.gif HTTP/1.0" 200 2326
229 <p>Each part of this log entry is described below.</p>
232 <dt><code>127.0.0.1</code> (<code>%h</code>)</dt>
234 <dd>This is the IP address of the client (remote host) which
235 made the request to the server. If <code class="directive"><a href="./mod/core.html#hostnamelookups">HostnameLookups</a></code> is
236 set to <code>On</code>, then the server will try to determine
237 the hostname and log it in place of the IP address. However,
238 this configuration is not recommended since it can
239 significantly slow the server. Instead, it is best to use a
240 log post-processor such as <code class="program"><a href="./programs/logresolve.html">logresolve</a></code> to determine
241 the hostnames. The IP address reported here is not
242 necessarily the address of the machine at which the user is
243 sitting. If a proxy server exists between the user and the
244 server, this address will be the address of the proxy, rather
245 than the originating machine.</dd>
247 <dt><code>-</code> (<code>%l</code>)</dt>
249 <dd>The "hyphen" in the output indicates that the requested
250 piece of information is not available. In this case, the
251 information that is not available is the RFC 1413 identity of
252 the client determined by <code>identd</code> on the clients
253 machine. This information is highly unreliable and should
254 almost never be used except on tightly controlled internal
255 networks. Apache httpd will not even attempt to determine
256 this information unless <code class="directive"><a href="./mod/core.html#identitycheck">IdentityCheck</a></code> is set
257 to <code>On</code>.</dd>
259 <dt><code>frank</code> (<code>%u</code>)</dt>
261 <dd>This is the userid of the person requesting the document
262 as determined by HTTP authentication. The same value is
263 typically provided to CGI scripts in the
264 <code>REMOTE_USER</code> environment variable. If the status
265 code for the request (see below) is 401, then this value
266 should not be trusted because the user is not yet
267 authenticated. If the document is not password protected,
268 this part will be "<code>-</code>" just like the previous
271 <dt><code>[10/Oct/2000:13:55:36 -0700]</code>
272 (<code>%t</code>)</dt>
275 The time that the request was received.
279 <code>[day/month/year:hour:minute:second zone]<br />
281 month = 3*letter<br />
284 minute = 2*digit<br />
285 second = 2*digit<br />
286 zone = (`+' | `-') 4*digit</code>
288 <p>It is possible to have the time displayed in another format
289 by specifying <code>%{format}t</code> in the log format
290 string, where <code>format</code> is either as in
291 <code>strftime(3)</code> from the C standard library,
292 or one of the supported special tokens. For details see
293 the <code class="module"><a href="./mod/mod_log_config.html">mod_log_config</a></code> <a href="mod/mod_log_config.html#formats">format strings</a>.</p>
296 <dt><code>"GET /apache_pb.gif HTTP/1.0"</code>
297 (<code>\"%r\"</code>)</dt>
299 <dd>The request line from the client is given in double
300 quotes. The request line contains a great deal of useful
301 information. First, the method used by the client is
302 <code>GET</code>. Second, the client requested the resource
303 <code>/apache_pb.gif</code>, and third, the client used the
304 protocol <code>HTTP/1.0</code>. It is also possible to log
305 one or more parts of the request line independently. For
306 example, the format string "<code>%m %U%q %H</code>" will log
307 the method, path, query-string, and protocol, resulting in
308 exactly the same output as "<code>%r</code>".</dd>
310 <dt><code>200</code> (<code>%>s</code>)</dt>
312 <dd>This is the status code that the server sends back to the
313 client. This information is very valuable, because it reveals
314 whether the request resulted in a successful response (codes
315 beginning in 2), a redirection (codes beginning in 3), an
316 error caused by the client (codes beginning in 4), or an
317 error in the server (codes beginning in 5). The full list of
318 possible status codes can be found in the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.txt">HTTP
319 specification</a> (RFC2616 section 10).</dd>
321 <dt><code>2326</code> (<code>%b</code>)</dt>
323 <dd>The last part indicates the size of the object returned
324 to the client, not including the response headers. If no
325 content was returned to the client, this value will be
326 "<code>-</code>". To log "<code>0</code>" for no content, use
327 <code>%B</code> instead.</dd>
331 <h3><a name="combined" id="combined">Combined Log Format</a></h3>
334 <p>Another commonly used format string is called the Combined
335 Log Format. It can be used as follows.</p>
337 <div class="example"><p><code>
338 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
339 \"%{User-agent}i\"" combined<br />
340 CustomLog log/access_log combined
343 <p>This format is exactly the same as the Common Log Format,
344 with the addition of two more fields. Each of the additional
345 fields uses the percent-directive
346 <code>%{<em>header</em>}i</code>, where <em>header</em> can be
347 any HTTP request header. The access log under this format will
350 <div class="example"><p><code>
351 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET
352 /apache_pb.gif HTTP/1.0" 200 2326
353 "http://www.example.com/start.html" "Mozilla/4.08 [en]
357 <p>The additional fields are:</p>
360 <dt><code>"http://www.example.com/start.html"</code>
361 (<code>\"%{Referer}i\"</code>)</dt>
363 <dd>The "Referer" (sic) HTTP request header. This gives the
364 site that the client reports having been referred from. (This
365 should be the page that links to or includes
366 <code>/apache_pb.gif</code>).</dd>
368 <dt><code>"Mozilla/4.08 [en] (Win98; I ;Nav)"</code>
369 (<code>\"%{User-agent}i\"</code>)</dt>
371 <dd>The User-Agent HTTP request header. This is the
372 identifying information that the client browser reports about
377 <h3><a name="multiple" id="multiple">Multiple Access Logs</a></h3>
380 <p>Multiple access logs can be created simply by specifying
381 multiple <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code>
382 directives in the configuration
383 file. For example, the following directives will create three
384 access logs. The first contains the basic CLF information,
385 while the second and third contain referer and browser
386 information. The last two <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code> lines show how
387 to mimic the effects of the <code>ReferLog</code> and <code>AgentLog</code> directives.</p>
389 <div class="example"><p><code>
390 LogFormat "%h %l %u %t \"%r\" %>s %b" common<br />
391 CustomLog logs/access_log common<br />
392 CustomLog logs/referer_log "%{Referer}i -> %U"<br />
393 CustomLog logs/agent_log "%{User-agent}i"
396 <p>This example also shows that it is not necessary to define a
397 nickname with the <code class="directive"><a href="./mod/mod_log_config.html#logformat">LogFormat</a></code> directive. Instead,
398 the log format can be specified directly in the <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code> directive.</p>
401 <h3><a name="conditional" id="conditional">Conditional Logs</a></h3>
404 <p>There are times when it is convenient to exclude certain
405 entries from the access logs based on characteristics of the
406 client request. This is easily accomplished with the help of <a href="env.html">environment variables</a>. First, an
407 environment variable must be set to indicate that the request
408 meets certain conditions. This is usually accomplished with
409 <code class="directive"><a href="./mod/mod_setenvif.html#setenvif">SetEnvIf</a></code>. Then the
410 <code>env=</code> clause of the <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code> directive is used to
411 include or exclude requests where the environment variable is
412 set. Some examples:</p>
414 <div class="example"><p><code>
415 # Mark requests from the loop-back interface<br />
416 SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog<br />
417 # Mark requests for the robots.txt file<br />
418 SetEnvIf Request_URI "^/robots\.txt$" dontlog<br />
419 # Log what remains<br />
420 CustomLog logs/access_log common env=!dontlog
423 <p>As another example, consider logging requests from
424 english-speakers to one log file, and non-english speakers to a
425 different log file.</p>
427 <div class="example"><p><code>
428 SetEnvIf Accept-Language "en" english<br />
429 CustomLog logs/english_log common env=english<br />
430 CustomLog logs/non_english_log common env=!english
433 <p>In a caching scenario one would want to know about
434 the efficiency of the cache. A very simple method to
435 find this out would be:</p>
437 <div class="example"><p><code>
438 SetEnv CACHE_MISS 1<br />
439 LogFormat "%h %l %u %t "%r " %>s %b %{CACHE_MISS}e" common-cache<br />
440 CustomLog logs/access_log common-cache
443 <p><code class="module"><a href="./mod/mod_cache.html">mod_cache</a></code> will run before
444 <code class="module"><a href="./mod/mod_env.html">mod_env</a></code> and when successfull will deliver the
445 content without it. In that case a cache hit will log
446 <code>-</code>, while a cache miss will log <code>1</code>.</p>
448 <p>Although we have just shown that conditional logging is very
449 powerful and flexible, it is not the only way to control the
450 contents of the logs. Log files are more useful when they
451 contain a complete record of server activity. It is often
452 easier to simply post-process the log files to remove requests
453 that you do not want to consider.</p>
455 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
456 <div class="section">
457 <h2><a name="rotation" id="rotation">Log Rotation</a></h2>
460 <p>On even a moderately busy server, the quantity of
461 information stored in the log files is very large. The access
462 log file typically grows 1 MB or more per 10,000 requests. It
463 will consequently be necessary to periodically rotate the log
464 files by moving or deleting the existing logs. This cannot be
465 done while the server is running, because Apache httpd will continue
466 writing to the old log file as long as it holds the file open.
467 Instead, the server must be <a href="stopping.html">restarted</a> after the log files are
468 moved or deleted so that it will open new log files.</p>
470 <p>By using a <em>graceful</em> restart, the server can be
471 instructed to open new log files without losing any existing or
472 pending connections from clients. However, in order to
473 accomplish this, the server must continue to write to the old
474 log files while it finishes serving old requests. It is
475 therefore necessary to wait for some time after the restart
476 before doing any processing on the log files. A typical
477 scenario that simply rotates the logs and compresses the old
478 logs to save space is:</p>
480 <div class="example"><p><code>
481 mv access_log access_log.old<br />
482 mv error_log error_log.old<br />
483 apachectl graceful<br />
485 gzip access_log.old error_log.old
488 <p>Another way to perform log rotation is using <a href="#piped">piped logs</a> as discussed in the next
490 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
491 <div class="section">
492 <h2><a name="piped" id="piped">Piped Logs</a></h2>
495 <p>Apache httpd is capable of writing error and access log
496 files through a pipe to another process, rather than directly
497 to a file. This capability dramatically increases the
498 flexibility of logging, without adding code to the main server.
499 In order to write logs to a pipe, simply replace the filename
500 with the pipe character "<code>|</code>", followed by the name
501 of the executable which should accept log entries on its
502 standard input. The server will start the piped-log process when
503 the server starts, and will restart it if it crashes while the
504 server is running. (This last feature is why we can refer to
505 this technique as "reliable piped logging".)</p>
507 <p>Piped log processes are spawned by the parent Apache httpd
508 process, and inherit the userid of that process. This means
509 that piped log programs usually run as root. It is therefore
510 very important to keep the programs simple and secure.</p>
512 <p>One important use of piped logs is to allow log rotation
513 without having to restart the server. The Apache HTTP Server
514 includes a simple program called <code class="program"><a href="./programs/rotatelogs.html">rotatelogs</a></code>
515 for this purpose. For example, to rotate the logs every 24 hours, you
518 <div class="example"><p><code>
519 CustomLog "|/usr/local/apache/bin/rotatelogs
520 /var/log/access_log 86400" common
523 <p>Notice that quotes are used to enclose the entire command
524 that will be called for the pipe. Although these examples are
525 for the access log, the same technique can be used for the
528 <p>A similar but much more flexible log rotation program
529 called <a href="http://www.cronolog.org/">cronolog</a>
530 is available at an external site.</p>
532 <p>As with conditional logging, piped logs are a very powerful
533 tool, but they should not be used where a simpler solution like
534 off-line post-processing is available.</p>
536 <p>By default the piped log process is spawned without invoking
537 a shell. Use "<code>|$</code>" instead of "<code>|</code>"
538 to spawn using a shell (usually with <code>/bin/sh -c</code>):</p>
540 <div class="example"><p><code>
541 # Invoke "rotatelogs" using a shell
542 CustomLog "|$/usr/local/apache/bin/rotatelogs
543 /var/log/access_log 86400" common
546 <p>This was the default behaviour for Apache 2.2.
547 Depending on the shell specifics this might lead to
548 an additional shell process for the lifetime of the logging
549 pipe program and signal handling problems during restart.
550 For compatibility reasons with Apache 2.2 the notation
551 "<code>||</code>" is also supported and equivalent to using
552 "<code>|</code>".</p>
553 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
554 <div class="section">
555 <h2><a name="virtualhost" id="virtualhost">Virtual Hosts</a></h2>
558 <p>When running a server with many <a href="vhosts/">virtual
559 hosts</a>, there are several options for dealing with log
560 files. First, it is possible to use logs exactly as in a
561 single-host server. Simply by placing the logging directives
562 outside the <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code> sections in the
563 main server context, it is possible to log all requests in the
564 same access log and error log. This technique does not allow
565 for easy collection of statistics on individual virtual
568 <p>If <code class="directive"><a href="./mod/mod_log_config.html#customlog">CustomLog</a></code>
569 or <code class="directive"><a href="./mod/core.html#errorlog">ErrorLog</a></code>
570 directives are placed inside a
571 <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code>
572 section, all requests or errors for that virtual host will be
573 logged only to the specified file. Any virtual host which does
574 not have logging directives will still have its requests sent
575 to the main server logs. This technique is very useful for a
576 small number of virtual hosts, but if the number of hosts is
577 very large, it can be complicated to manage. In addition, it
578 can often create problems with <a href="vhosts/fd-limits.html">insufficient file
581 <p>For the access log, there is a very good compromise. By
582 adding information on the virtual host to the log format
583 string, it is possible to log all hosts to the same log, and
584 later split the log into individual files. For example,
585 consider the following directives.</p>
587 <div class="example"><p><code>
588 LogFormat "%v %l %u %t \"%r\" %>s %b"
590 CustomLog logs/access_log comonvhost
593 <p>The <code>%v</code> is used to log the name of the virtual
594 host that is serving the request. Then a program like <a href="programs/other.html">split-logfile</a> can be used to
595 post-process the access log in order to split it into one file
596 per virtual host.</p>
597 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
598 <div class="section">
599 <h2><a name="other" id="other">Other Log Files</a></h2>
602 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/mod_logio.html">mod_logio</a></code></li><li><code class="module"><a href="./mod/mod_log_forensic.html">mod_log_forensic</a></code></li><li><code class="module"><a href="./mod/mod_cgi.html">mod_cgi</a></code></li><li><code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/mod_log_config.html#logformat">LogFormat</a></code></li><li><code class="directive"><a href="./mod/mod_log_forensic.html#forensiclog">ForensicLog</a></code></li><li><code class="directive"><a href="./mod/mpm_common.html#pidfile">PidFile</a></code></li><li><code class="directive"><a href="./mod/mod_rewrite.html#rewritelog">RewriteLog</a></code></li><li><code class="directive"><a href="./mod/mod_rewrite.html#rewriteloglevel">RewriteLogLevel</a></code></li><li><code class="directive"><a href="./mod/mod_cgi.html#scriptlog">ScriptLog</a></code></li><li><code class="directive"><a href="./mod/mod_cgi.html#scriptlogbuffer">ScriptLogBuffer</a></code></li><li><code class="directive"><a href="./mod/mod_cgi.html#scriptloglength">ScriptLogLength</a></code></li></ul></td></tr></table>
604 <h3>Logging actual bytes sent and received</h3>
607 <p><code class="module"><a href="./mod/mod_logio.html">mod_logio</a></code> adds in two additional
608 <code class="directive"><a href="./mod/mod_log_config.html#logformat">LogFormat</a></code> fields
609 (%I and %O) that log the actual number of bytes received and sent
613 <h3>Forensic Logging</h3>
616 <p><code class="module"><a href="./mod/mod_log_forensic.html">mod_log_forensic</a></code> provides for forensic logging of
617 client requests. Logging is done before and after processing a
618 request, so the forensic log contains two log lines for each
619 request. The forensic logger is very strict with no customizations.
620 It can be an invaluable debugging and security tool.</p>
623 <h3><a name="pidfile" id="pidfile">PID File</a></h3>
626 <p>On startup, Apache httpd saves the process id of the parent
627 httpd process to the file <code>logs/httpd.pid</code>. This
628 filename can be changed with the <code class="directive"><a href="./mod/mpm_common.html#pidfile">PidFile</a></code> directive. The
629 process-id is for use by the administrator in restarting and
630 terminating the daemon by sending signals to the parent
631 process; on Windows, use the -k command line option instead.
632 For more information see the <a href="stopping.html">Stopping
633 and Restarting</a> page.</p>
636 <h3><a name="scriptlog" id="scriptlog">Script Log</a></h3>
639 <p>In order to aid in debugging, the
640 <code class="directive"><a href="./mod/mod_cgi.html#scriptlog">ScriptLog</a></code> directive
641 allows you to record the input to and output from CGI scripts.
642 This should only be used in testing - not for live servers.
643 More information is available in the <a href="mod/mod_cgi.html">mod_cgi</a> documentation.</p>
646 <h3><a name="rewritelog" id="rewritelog">Rewrite Log</a></h3>
649 <p>When using the powerful and complex features of <a href="mod/mod_rewrite.html">mod_rewrite</a>, it is almost
650 always necessary to use the <code class="directive"><a href="./mod/mod_rewrite.html#rewritelog">RewriteLog</a></code> to help
651 in debugging. This log file produces a detailed analysis of how
652 the rewriting engine transforms requests. The level of detail
653 is controlled by the <code class="directive"><a href="./mod/mod_rewrite.html#rewriteloglevel">RewriteLogLevel</a></code> directive.</p>
656 <div class="bottomlang">
657 <p><span>Available Languages: </span><a href="./en/logs.html" title="English"> en </a> |
658 <a href="./fr/logs.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
659 <a href="./ja/logs.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
660 <a href="./ko/logs.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
661 <a href="./tr/logs.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
662 </div><div id="footer">
663 <p class="apache">Copyright 2010 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>
664 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div>