]> granicus.if.org Git - apache/blob - docs/manual/logs.xml
Remove useless <br \> in highlight blocks.
[apache] / docs / manual / logs.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="logs.xml.meta">
24
25   <title>Log Files</title>
26
27   <summary>
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
34     contain.</p>
35   </summary>
36
37     <section id="overview">
38     <title>Overview</title>
39
40   <related>
41       <modulelist>
42         <module>mod_log_config</module>
43         <module>mod_log_forensic</module>
44         <module>mod_logio</module>
45         <module>mod_cgi</module>
46       </modulelist>
47   </related>
48
49   <p>
50   The Apache HTTP Server provides a variety of different mechanisms for
51   logging everything that happens on your server, from the initial
52   request, through the URL mapping process, to the final resolution of
53   the connection, including any errors that may have occurred in the
54   process. In addition to this, third-party modules may provide logging
55   capabilities, or inject entries into the existing log files, and
56   applications such as CGI programs, or PHP scripts, or other handlers,
57   may send messages to the server error log.
58   </p>
59
60   <p>
61   In this document we discuss the logging modules that are a standard
62   part of the http server.
63   </p>
64
65   </section>
66
67   <section id="security">
68     <title>Security Warning</title>
69
70     <p>Anyone who can write to the directory where Apache httpd is
71     writing a log file can almost certainly gain access to the uid
72     that the server is started as, which is normally root. Do
73     <em>NOT</em> give people write access to the directory the logs
74     are stored in without being aware of the consequences; see the
75     <a href="misc/security_tips.html">security tips</a> document
76     for details.</p>
77
78     <p>In addition, log files may contain information supplied
79     directly by the client, without escaping. Therefore, it is
80     possible for malicious clients to insert control-characters in
81     the log files, so care must be taken in dealing with raw
82     logs.</p>
83   </section>
84
85   <section id="errorlog">
86     <title>Error Log</title>
87
88     <related>
89       <modulelist>
90         <module>core</module>
91       </modulelist>
92       <directivelist>
93         <directive module="core">ErrorLog</directive>
94         <directive module="core">ErrorLogFormat</directive>
95         <directive module="core">LogLevel</directive>
96       </directivelist>
97     </related>
98
99     <p>The server error log, whose name and location is set by the
100     <directive module="core">ErrorLog</directive> directive, is the
101     most important log file. This is the place where Apache httpd
102     will send diagnostic information and record any errors that it
103     encounters in processing requests. It is the first place to
104     look when a problem occurs with starting the server or with the
105     operation of the server, since it will often contain details of
106     what went wrong and how to fix it.</p>
107
108     <p>The error log is usually written to a file (typically
109     <code>error_log</code> on Unix systems and
110     <code>error.log</code> on Windows and OS/2). On Unix systems it
111     is also possible to have the server send errors to
112     <code>syslog</code> or <a href="#piped">pipe them to a
113     program</a>.</p>
114
115     <p>The format of the error log is defined by the <directive
116     module="core">ErrorLogFormat</directive> directive, with which you
117     can customize what values are logged. A default is format defined
118     if you don't specify one. A typical log message follows:</p>
119
120     <example>
121     [Fri Sep 09 10:42:29.902022 2011] [core:error] [pid 35708:tid 4328636416]
122     [client 72.15.99.187] File does not exist: /usr/local/apache2/htdocs/favicon.ico
123     </example>
124
125     <p>The first item in the log entry is the date and time of the
126     message. The next is the module producing the message (core, in this
127     case) and the severity level of that message. This is followed by
128     the process ID and, if appropriate, the thread ID, of the process
129     that experienced the condition. Next, we have the client address
130     that made the request. And finally is the detailed error message,
131     which in this case indicates a request for a file that did not
132     exist.</p>
133
134     <p>A very wide variety of different messages can appear in the
135     error log. Most look similar to the example above. The error
136     log will also contain debugging output from CGI scripts. Any
137     information written to <code>stderr</code> by a CGI script will
138     be copied directly to the error log.</p>
139
140     <p>Putting a <code>%L</code> token in both the error log and the access
141     log will produce a log entry ID with which you can correlate the entry
142     in the error log with the entry in the access log. If
143     <module>mod_unique_id</module> is loaded, its unique request ID will be
144     used as the log entry ID, too.</p>
145
146     <p>During testing, it is often useful to continuously monitor
147     the error log for any problems. On Unix systems, you can
148     accomplish this using:</p>
149
150     <example>
151       tail -f error_log
152     </example>
153   </section>
154
155   <section id="permodule">
156     <title>Per-module logging</title>
157
158     <p>The <directive module="core">LogLevel</directive> directive
159     allows you to specify a log severity level on a per-module basis. In
160     this way, if you are troubleshooting a problem with just one
161     particular module, you can turn up its logging volume without also
162     getting the details of other modules that you're not interested in.
163     This is particularly useful for modules such as
164     <module>mod_proxy</module> or <module>mod_rewrite</module> where you
165     want to know details about what it's trying to do.</p>
166
167     <p>Do this by specifying the name of the module in your
168     <directive>LogLevel</directive> directive:</p>
169
170     <highlight language="config">
171     LogLevel info rewrite:trace5
172     </highlight>
173
174     <p>This sets the main <directive>LogLevel</directive> to info, but
175     turns it up to <code>trace5</code> for
176     <module>mod_rewrite</module>.</p>
177
178     <note>This replaces the per-module logging directives, such as
179     <code>RewriteLog</code>, that were present in earlier versions of
180     the server.</note>
181   </section>
182
183   <section id="accesslog">
184     <title>Access Log</title>
185
186     <related>
187       <modulelist>
188         <module>mod_log_config</module>
189         <module>mod_setenvif</module>
190       </modulelist>
191       <directivelist>
192         <directive module="mod_log_config">CustomLog</directive>
193         <directive module="mod_log_config">LogFormat</directive>
194         <directive module="mod_setenvif">SetEnvIf</directive>
195       </directivelist>
196     </related>
197
198     <p>The server access log records all requests processed by the
199     server. The location and content of the access log are
200     controlled by the <directive module="mod_log_config">CustomLog</directive>
201     directive. The <directive module="mod_log_config">LogFormat</directive>
202     directive can be used to simplify the selection of
203     the contents of the logs. This section describes how to configure the server
204     to record information in the access log.</p>
205
206     <p>Of course, storing the information in the access log is only
207     the start of log management. The next step is to analyze this
208     information to produce useful statistics. Log analysis in
209     general is beyond the scope of this document, and not really
210     part of the job of the web server itself. For more information
211     about this topic, and for applications which perform log
212     analysis, check the <a
213     href="http://dmoz.org/Computers/Software/Internet/Site_Management/Log_Analysis/">
214     Open Directory</a>.
215     </p>
216
217     <p>Various versions of Apache httpd have used other modules and
218     directives to control access logging, including
219     mod_log_referer, mod_log_agent, and the
220     <code>TransferLog</code> directive. The <directive
221     module="mod_log_config">CustomLog</directive> directive now subsumes
222     the functionality of all the older directives.</p>
223
224     <p>The format of the access log is highly configurable. The format
225     is specified using a format string that looks much like a C-style
226     printf(1) format string. Some examples are presented in the next
227     sections. For a complete list of the possible contents of the
228     format string, see the <module>mod_log_config</module> <a
229     href="mod/mod_log_config.html#formats">format strings</a>.</p>
230
231     <section id="common">
232       <title>Common Log Format</title>
233
234       <p>A typical configuration for the access log might look as
235       follows.</p>
236
237       <highlight language="config">
238 LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
239 CustomLog logs/access_log common
240       </highlight>
241
242       <p>This defines the <em>nickname</em> <code>common</code> and
243       associates it with a particular log format string. The format
244       string consists of percent directives, each of which tell the
245       server to log a particular piece of information. Literal
246       characters may also be placed in the format string and will be
247       copied directly into the log output. The quote character
248       (<code>"</code>) must be escaped by placing a backslash before
249       it to prevent it from being interpreted as the end of the
250       format string. The format string may also contain the special
251       control characters "<code>\n</code>" for new-line and
252       "<code>\t</code>" for tab.</p>
253
254       <p>The <directive module="mod_log_config">CustomLog</directive>
255       directive sets up a new log file using the defined
256       <em>nickname</em>. The filename for the access log is relative to
257       the <directive module="core">ServerRoot</directive> unless it
258       begins with a slash.</p>
259
260       <p>The above configuration will write log entries in a format
261       known as the Common Log Format (CLF). This standard format can
262       be produced by many different web servers and read by many log
263       analysis programs. The log file entries produced in CLF will
264       look something like this:</p>
265
266       <example>
267         127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET
268         /apache_pb.gif HTTP/1.0" 200 2326
269       </example>
270
271       <p>Each part of this log entry is described below.</p>
272
273       <dl>
274         <dt><code>127.0.0.1</code> (<code>%h</code>)</dt>
275
276         <dd>This is the IP address of the client (remote host) which
277         made the request to the server. If <directive
278         module="core">HostnameLookups</directive> is
279         set to <code>On</code>, then the server will try to determine
280         the hostname and log it in place of the IP address. However,
281         this configuration is not recommended since it can
282         significantly slow the server. Instead, it is best to use a
283         log post-processor such as <program>logresolve</program> to determine
284         the hostnames. The IP address reported here is not
285         necessarily the address of the machine at which the user is
286         sitting. If a proxy server exists between the user and the
287         server, this address will be the address of the proxy, rather
288         than the originating machine.</dd>
289
290         <dt><code>-</code> (<code>%l</code>)</dt>
291
292         <dd>The "hyphen" in the output indicates that the requested
293         piece of information is not available. In this case, the
294         information that is not available is the RFC 1413 identity of
295         the client determined by <code>identd</code> on the clients
296         machine. This information is highly unreliable and should
297         almost never be used except on tightly controlled internal
298         networks. Apache httpd will not even attempt to determine
299         this information unless <directive
300         module="mod_ident">IdentityCheck</directive> is set
301         to <code>On</code>.</dd>
302
303         <dt><code>frank</code> (<code>%u</code>)</dt>
304
305         <dd>This is the userid of the person requesting the document
306         as determined by HTTP authentication. The same value is
307         typically provided to CGI scripts in the
308         <code>REMOTE_USER</code> environment variable. If the status
309         code for the request (see below) is 401, then this value
310         should not be trusted because the user is not yet
311         authenticated. If the document is not password protected,
312         this part will be "<code>-</code>" just like the previous
313         one.</dd>
314
315         <dt><code>[10/Oct/2000:13:55:36 -0700]</code>
316         (<code>%t</code>)</dt>
317
318         <dd>
319           The time that the request was received.
320           The format is:
321
322           <p class="indent">
323             <code>[day/month/year:hour:minute:second zone]<br />
324              day = 2*digit<br />
325              month = 3*letter<br />
326              year = 4*digit<br />
327              hour = 2*digit<br />
328              minute = 2*digit<br />
329              second = 2*digit<br />
330              zone = (`+' | `-') 4*digit</code>
331           </p>
332           <p>It is possible to have the time displayed in another format
333           by specifying <code>%{format}t</code> in the log format
334           string, where <code>format</code> is either as in
335           <code>strftime(3)</code> from the C standard library,
336           or one of the supported special tokens. For details see
337           the <module>mod_log_config</module> <a
338           href="mod/mod_log_config.html#formats">format strings</a>.</p>
339         </dd>
340
341         <dt><code>"GET /apache_pb.gif HTTP/1.0"</code>
342         (<code>\"%r\"</code>)</dt>
343
344         <dd>The request line from the client is given in double
345         quotes. The request line contains a great deal of useful
346         information. First, the method used by the client is
347         <code>GET</code>. Second, the client requested the resource
348         <code>/apache_pb.gif</code>, and third, the client used the
349         protocol <code>HTTP/1.0</code>. It is also possible to log
350         one or more parts of the request line independently. For
351         example, the format string "<code>%m %U%q %H</code>" will log
352         the method, path, query-string, and protocol, resulting in
353         exactly the same output as "<code>%r</code>".</dd>
354
355         <dt><code>200</code> (<code>%&gt;s</code>)</dt>
356
357         <dd>This is the status code that the server sends back to the
358         client. This information is very valuable, because it reveals
359         whether the request resulted in a successful response (codes
360         beginning in 2), a redirection (codes beginning in 3), an
361         error caused by the client (codes beginning in 4), or an
362         error in the server (codes beginning in 5). The full list of
363         possible status codes can be found in the <a
364         href="http://www.w3.org/Protocols/rfc2616/rfc2616.txt">HTTP
365         specification</a> (RFC2616 section 10).</dd>
366
367         <dt><code>2326</code> (<code>%b</code>)</dt>
368
369         <dd>The last part indicates the size of the object returned
370         to the client, not including the response headers. If no
371         content was returned to the client, this value will be
372         "<code>-</code>". To log "<code>0</code>" for no content, use
373         <code>%B</code> instead.</dd>
374       </dl>
375     </section>
376
377     <section id="combined">
378       <title>Combined Log Format</title>
379
380       <p>Another commonly used format string is called the Combined
381       Log Format. It can be used as follows.</p>
382
383       <highlight language="config">
384 LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
385 CustomLog log/access_log combined
386       </highlight>
387
388       <p>This format is exactly the same as the Common Log Format,
389       with the addition of two more fields. Each of the additional
390       fields uses the percent-directive
391       <code>%{<em>header</em>}i</code>, where <em>header</em> can be
392       any HTTP request header. The access log under this format will
393       look like:</p>
394
395       <example>
396         127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET
397         /apache_pb.gif HTTP/1.0" 200 2326
398         "http://www.example.com/start.html" "Mozilla/4.08 [en]
399         (Win98; I ;Nav)"
400       </example>
401
402       <p>The additional fields are:</p>
403
404       <dl>
405         <dt><code>"http://www.example.com/start.html"</code>
406         (<code>\"%{Referer}i\"</code>)</dt>
407
408         <dd>The "Referer" (sic) HTTP request header. This gives the
409         site that the client reports having been referred from. (This
410         should be the page that links to or includes
411         <code>/apache_pb.gif</code>).</dd>
412
413         <dt><code>"Mozilla/4.08 [en] (Win98; I ;Nav)"</code>
414         (<code>\"%{User-agent}i\"</code>)</dt>
415
416         <dd>The User-Agent HTTP request header. This is the
417         identifying information that the client browser reports about
418         itself.</dd>
419       </dl>
420     </section>
421
422     <section id="multiple">
423       <title>Multiple Access Logs</title>
424
425       <p>Multiple access logs can be created simply by specifying
426       multiple <directive module="mod_log_config">CustomLog</directive>
427       directives in the configuration
428       file. For example, the following directives will create three
429       access logs. The first contains the basic CLF information,
430       while the second and third contain referer and browser
431       information. The last two <directive
432       module="mod_log_config">CustomLog</directive> lines show how
433       to mimic the effects of the <code>ReferLog</code> and <code
434       >AgentLog</code> directives.</p>
435
436       <highlight language="config">
437 LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
438 CustomLog logs/access_log common
439 CustomLog logs/referer_log "%{Referer}i -&gt; %U"
440 CustomLog logs/agent_log "%{User-agent}i"
441       </highlight>
442
443       <p>This example also shows that it is not necessary to define a
444       nickname with the <directive
445       module="mod_log_config">LogFormat</directive> directive. Instead,
446       the log format can be specified directly in the <directive
447       module="mod_log_config">CustomLog</directive> directive.</p>
448     </section>
449
450     <section id="conditional">
451       <title>Conditional Logs</title>
452
453       <p>There are times when it is convenient to exclude certain
454       entries from the access logs based on characteristics of the
455       client request. This is easily accomplished with the help of <a
456       href="env.html">environment variables</a>. First, an
457       environment variable must be set to indicate that the request
458       meets certain conditions. This is usually accomplished with
459       <directive module="mod_setenvif">SetEnvIf</directive>. Then the
460       <code>env=</code> clause of the <directive
461       module="mod_log_config">CustomLog</directive> directive is used to
462       include or exclude requests where the environment variable is
463       set. Some examples:</p>
464
465       <highlight language="config">
466 # Mark requests from the loop-back interface
467 SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
468 # Mark requests for the robots.txt file
469 SetEnvIf Request_URI "^/robots\.txt$" dontlog
470 # Log what remains
471 CustomLog logs/access_log common env=!dontlog
472       </highlight>
473
474       <p>As another example, consider logging requests from
475       english-speakers to one log file, and non-english speakers to a
476       different log file.</p>
477
478       <highlight language="config">
479 SetEnvIf Accept-Language "en" english
480 CustomLog logs/english_log common env=english
481 CustomLog logs/non_english_log common env=!english
482       </highlight>
483
484       <p>In a caching scenario one would want to know about
485       the efficiency of the cache. A very simple method to
486       find this out would be:</p>
487
488       <highlight language="config">
489 SetEnv CACHE_MISS 1
490 LogFormat "%h %l %u %t "%r " %>s %b %{CACHE_MISS}e" common-cache
491 CustomLog logs/access_log common-cache
492       </highlight>
493
494       <p><module>mod_cache</module> will run before
495       <module>mod_env</module> and, when successful, will deliver the
496       content without it. In that case a cache hit will log
497       <code>-</code>, while a cache miss will log <code>1</code>.</p>
498
499       <p>In addition to the <code>env=</code> syntax, <directive
500       module="mod_log_config">LogFormat</directive> supports logging values
501       conditional upon the HTTP response code:</p>
502
503       <highlight language="config">
504 LogFormat "%400,501{User-agent}i" browserlog
505 LogFormat "%!200,304,302{Referer}i" refererlog
506       </highlight>
507
508       <p>In the first example, the <code>User-agent</code> will be
509       logged if the HTTP status code is 400 or 501. In other cases, a
510       literal "-" will be logged instead. Likewise, in the second
511       example, the <code>Referer</code> will be logged if the HTTP
512       status code is <strong>not</strong> 200, 204, or 302. (Note the
513       "!" before the status codes.</p>
514
515       <p>Although we have just shown that conditional logging is very
516       powerful and flexible, it is not the only way to control the
517       contents of the logs. Log files are more useful when they
518       contain a complete record of server activity. It is often
519       easier to simply post-process the log files to remove requests
520       that you do not want to consider.</p>
521     </section>
522   </section>
523
524   <section id="rotation">
525     <title>Log Rotation</title>
526
527     <p>On even a moderately busy server, the quantity of
528     information stored in the log files is very large. The access
529     log file typically grows 1 MB or more per 10,000 requests. It
530     will consequently be necessary to periodically rotate the log
531     files by moving or deleting the existing logs. This cannot be
532     done while the server is running, because Apache httpd will continue
533     writing to the old log file as long as it holds the file open.
534     Instead, the server must be <a
535     href="stopping.html">restarted</a> after the log files are
536     moved or deleted so that it will open new log files.</p>
537
538     <p>By using a <em>graceful</em> restart, the server can be
539     instructed to open new log files without losing any existing or
540     pending connections from clients. However, in order to
541     accomplish this, the server must continue to write to the old
542     log files while it finishes serving old requests. It is
543     therefore necessary to wait for some time after the restart
544     before doing any processing on the log files. A typical
545     scenario that simply rotates the logs and compresses the old
546     logs to save space is:</p>
547
548     <example>
549       mv access_log access_log.old<br />
550       mv error_log error_log.old<br />
551       apachectl graceful<br />
552       sleep 600<br />
553       gzip access_log.old error_log.old
554     </example>
555
556     <p>Another way to perform log rotation is using <a
557     href="#piped">piped logs</a> as discussed in the next
558     section.</p>
559   </section>
560
561   <section id="piped">
562     <title>Piped Logs</title>
563
564     <p>Apache httpd is capable of writing error and access log
565     files through a pipe to another process, rather than directly
566     to a file. This capability dramatically increases the
567     flexibility of logging, without adding code to the main server.
568     In order to write logs to a pipe, simply replace the filename
569     with the pipe character "<code>|</code>", followed by the name
570     of the executable which should accept log entries on its
571     standard input. The server will start the piped-log process when
572     the server starts, and will restart it if it crashes while the
573     server is running. (This last feature is why we can refer to
574     this technique as "reliable piped logging".)</p>
575
576     <p>Piped log processes are spawned by the parent Apache httpd
577     process, and inherit the userid of that process. This means
578     that piped log programs usually run as root. It is therefore
579     very important to keep the programs simple and secure.</p>
580
581     <p>One important use of piped logs is to allow log rotation
582     without having to restart the server. The Apache HTTP Server
583     includes a simple program called <program>rotatelogs</program>
584     for this purpose. For example, to rotate the logs every 24 hours, you
585     can use:</p>
586
587     <highlight language="config">
588       CustomLog "|/usr/local/apache/bin/rotatelogs /var/log/access_log 86400" common
589     </highlight>
590
591     <p>Notice that quotes are used to enclose the entire command
592     that will be called for the pipe. Although these examples are
593     for the access log, the same technique can be used for the
594     error log.</p>
595
596     <p>As with conditional logging, piped logs are a very powerful
597     tool, but they should not be used where a simpler solution like
598     off-line post-processing is available.</p>
599
600     <p>By default the piped log process is spawned without invoking
601     a shell. Use "<code>|$</code>" instead of "<code>|</code>"
602     to spawn using a shell (usually with <code>/bin/sh -c</code>):</p>
603
604     <highlight language="config">
605 # Invoke "rotatelogs" using a shell
606 CustomLog "|$/usr/local/apache/bin/rotatelogs   /var/log/access_log 86400" common
607     </highlight>
608
609     <p>This was the default behaviour for Apache 2.2.
610     Depending on the shell specifics this might lead to
611     an additional shell process for the lifetime of the logging
612     pipe program and signal handling problems during restart.
613     For compatibility reasons with Apache 2.2 the notation
614     "<code>||</code>" is also supported and equivalent to using
615     "<code>|</code>".</p>
616
617     <note><title>Windows note</title>
618     <p>Note that on Windows, you may run into problems when running many piped
619     logger processes, especially when HTTPD is running as a service. This is
620     caused by running out of desktop heap space. The desktop heap space given
621     to each service is specified by the third argument to the
622     <code>SharedSection</code> parameter in the
623     HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SessionManager\SubSystems\Windows
624     registry value. <strong>Change this value with care</strong>; the normal
625     caveats for changing the Windows registry apply, but you might also exhaust
626     the desktop heap pool if the number is adjusted too high.</p>
627     </note>
628   </section>
629
630   <section id="virtualhost">
631     <title>Virtual Hosts</title>
632
633     <p>When running a server with many <a href="vhosts/">virtual
634     hosts</a>, there are several options for dealing with log
635     files. First, it is possible to use logs exactly as in a
636     single-host server. Simply by placing the logging directives
637     outside the <directive module="core"
638     type="section">VirtualHost</directive> sections in the
639     main server context, it is possible to log all requests in the
640     same access log and error log. This technique does not allow
641     for easy collection of statistics on individual virtual
642     hosts.</p>
643
644     <p>If <directive module="mod_log_config">CustomLog</directive>
645     or <directive module="core">ErrorLog</directive>
646     directives are placed inside a
647     <directive module="core" type="section">VirtualHost</directive>
648     section, all requests or errors for that virtual host will be
649     logged only to the specified file. Any virtual host which does
650     not have logging directives will still have its requests sent
651     to the main server logs. This technique is very useful for a
652     small number of virtual hosts, but if the number of hosts is
653     very large, it can be complicated to manage. In addition, it
654     can often create problems with <a
655     href="vhosts/fd-limits.html">insufficient file
656     descriptors</a>.</p>
657
658     <p>For the access log, there is a very good compromise. By
659     adding information on the virtual host to the log format
660     string, it is possible to log all hosts to the same log, and
661     later split the log into individual files. For example,
662     consider the following directives.</p>
663
664     <highlight language="config">
665 LogFormat "%v %l %u %t \"%r\" %&gt;s %b" comonvhost
666 CustomLog logs/access_log comonvhost
667     </highlight>
668
669     <p>The <code>%v</code> is used to log the name of the virtual
670     host that is serving the request. Then a program like <a
671     href="programs/split-logfile.html">split-logfile</a> can be used to
672     post-process the access log in order to split it into one file
673     per virtual host.</p>
674   </section>
675
676   <section id="other">
677     <title>Other Log Files</title>
678
679     <related>
680       <modulelist>
681         <module>mod_logio</module>
682         <module>mod_log_config</module>
683         <module>mod_log_forensic</module>
684         <module>mod_cgi</module>
685       </modulelist>
686
687       <directivelist>
688         <directive module="mod_log_config">LogFormat</directive>
689         <directive module="mod_log_config">BufferedLogs</directive>
690         <directive module="mod_log_forensic">ForensicLog</directive>
691         <directive module="mpm_common">PidFile</directive>
692         <directive module="mod_cgi">ScriptLog</directive>
693         <directive module="mod_cgi">ScriptLogBuffer</directive>
694         <directive module="mod_cgi">ScriptLogLength</directive>
695       </directivelist>
696     </related>
697
698     <section>
699       <title>Logging actual bytes sent and received</title>
700
701       <p><module>mod_logio</module> adds in two additional
702          <directive module="mod_log_config">LogFormat</directive> fields
703          (%I and %O) that log the actual number of bytes received and sent
704          on the network.</p>
705     </section>
706
707     <section>
708       <title>Forensic Logging</title>
709
710       <p><module>mod_log_forensic</module> provides for forensic logging of
711          client requests. Logging is done before and after processing a
712          request, so the forensic log contains two log lines for each
713          request. The forensic logger is very strict with no customizations.
714          It can be an invaluable debugging and security tool.</p>
715     </section>
716
717     <section id="pidfile">
718       <title>PID File</title>
719
720       <p>On startup, Apache httpd saves the process id of the parent
721       httpd process to the file <code>logs/httpd.pid</code>. This
722       filename can be changed with the <directive
723       module="mpm_common">PidFile</directive> directive. The
724       process-id is for use by the administrator in restarting and
725       terminating the daemon by sending signals to the parent
726       process; on Windows, use the -k command line option instead.
727       For more information see the <a href="stopping.html">Stopping
728       and Restarting</a> page.</p>
729     </section>
730
731     <section id="scriptlog">
732       <title>Script Log</title>
733
734       <p>In order to aid in debugging, the
735       <directive module="mod_cgi">ScriptLog</directive> directive
736       allows you to record the input to and output from CGI scripts.
737       This should only be used in testing - not for live servers.
738       More information is available in the <a
739       href="mod/mod_cgi.html">mod_cgi</a> documentation.</p>
740     </section>
741
742   </section>
743 </manualpage>
744
745
746
747