]> granicus.if.org Git - apache/blob - docs/manual/logs.xml
Patch from info@mathijs.info to use 2.4 authz syntax.
[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> or <a
215     href="http://dir.yahoo.com/Computers_and_Internet/Software/Internet/World_Wide_Web/Servers/Log_Analysis_Tools/">
216     Yahoo</a>.</p>
217
218     <p>Various versions of Apache httpd have used other modules and
219     directives to control access logging, including
220     mod_log_referer, mod_log_agent, and the
221     <code>TransferLog</code> directive. The <directive
222     module="mod_log_config">CustomLog</directive> directive now subsumes
223     the functionality of all the older directives.</p>
224
225     <p>The format of the access log is highly configurable. The format
226     is specified using a format string that looks much like a C-style
227     printf(1) format string. Some examples are presented in the next
228     sections. For a complete list of the possible contents of the
229     format string, see the <module>mod_log_config</module> <a
230     href="mod/mod_log_config.html#formats">format strings</a>.</p>
231
232     <section id="common">
233       <title>Common Log Format</title>
234
235       <p>A typical configuration for the access log might look as
236       follows.</p>
237
238       <highlight language="config">
239 LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
240 CustomLog "logs/access_log" common
241       </highlight>
242
243       <p>This defines the <em>nickname</em> <code>common</code> and
244       associates it with a particular log format string. The format
245       string consists of percent directives, each of which tell the
246       server to log a particular piece of information. Literal
247       characters may also be placed in the format string and will be
248       copied directly into the log output. The quote character
249       (<code>"</code>) must be escaped by placing a backslash before
250       it to prevent it from being interpreted as the end of the
251       format string. The format string may also contain the special
252       control characters "<code>\n</code>" for new-line and
253       "<code>\t</code>" for tab.</p>
254
255       <p>The <directive module="mod_log_config">CustomLog</directive>
256       directive sets up a new log file using the defined
257       <em>nickname</em>. The filename for the access log is relative to
258       the <directive module="core">ServerRoot</directive> unless it
259       begins with a slash.</p>
260
261       <p>The above configuration will write log entries in a format
262       known as the Common Log Format (CLF). This standard format can
263       be produced by many different web servers and read by many log
264       analysis programs. The log file entries produced in CLF will
265       look something like this:</p>
266
267       <example>
268         127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET
269         /apache_pb.gif HTTP/1.0" 200 2326
270       </example>
271
272       <p>Each part of this log entry is described below.</p>
273
274       <dl>
275         <dt><code>127.0.0.1</code> (<code>%h</code>)</dt>
276
277         <dd>This is the IP address of the client (remote host) which
278         made the request to the server. If <directive
279         module="core">HostnameLookups</directive> is
280         set to <code>On</code>, then the server will try to determine
281         the hostname and log it in place of the IP address. However,
282         this configuration is not recommended since it can
283         significantly slow the server. Instead, it is best to use a
284         log post-processor such as <program>logresolve</program> to determine
285         the hostnames. The IP address reported here is not
286         necessarily the address of the machine at which the user is
287         sitting. If a proxy server exists between the user and the
288         server, this address will be the address of the proxy, rather
289         than the originating machine.</dd>
290
291         <dt><code>-</code> (<code>%l</code>)</dt>
292
293         <dd>The "hyphen" in the output indicates that the requested
294         piece of information is not available. In this case, the
295         information that is not available is the RFC 1413 identity of
296         the client determined by <code>identd</code> on the clients
297         machine. This information is highly unreliable and should
298         almost never be used except on tightly controlled internal
299         networks. Apache httpd will not even attempt to determine
300         this information unless <directive
301         module="mod_ident">IdentityCheck</directive> is set
302         to <code>On</code>.</dd>
303
304         <dt><code>frank</code> (<code>%u</code>)</dt>
305
306         <dd>This is the userid of the person requesting the document
307         as determined by HTTP authentication. The same value is
308         typically provided to CGI scripts in the
309         <code>REMOTE_USER</code> environment variable. If the status
310         code for the request (see below) is 401, then this value
311         should not be trusted because the user is not yet
312         authenticated. If the document is not password protected,
313         this part will be "<code>-</code>" just like the previous
314         one.</dd>
315
316         <dt><code>[10/Oct/2000:13:55:36 -0700]</code>
317         (<code>%t</code>)</dt>
318
319         <dd>
320           The time that the request was received.
321           The format is:
322
323           <p class="indent">
324             <code>[day/month/year:hour:minute:second zone]<br />
325              day = 2*digit<br />
326              month = 3*letter<br />
327              year = 4*digit<br />
328              hour = 2*digit<br />
329              minute = 2*digit<br />
330              second = 2*digit<br />
331              zone = (`+' | `-') 4*digit</code>
332           </p>
333           <p>It is possible to have the time displayed in another format
334           by specifying <code>%{format}t</code> in the log format
335           string, where <code>format</code> is either as in
336           <code>strftime(3)</code> from the C standard library,
337           or one of the supported special tokens. For details see
338           the <module>mod_log_config</module> <a
339           href="mod/mod_log_config.html#formats">format strings</a>.</p>
340         </dd>
341
342         <dt><code>"GET /apache_pb.gif HTTP/1.0"</code>
343         (<code>\"%r\"</code>)</dt>
344
345         <dd>The request line from the client is given in double
346         quotes. The request line contains a great deal of useful
347         information. First, the method used by the client is
348         <code>GET</code>. Second, the client requested the resource
349         <code>/apache_pb.gif</code>, and third, the client used the
350         protocol <code>HTTP/1.0</code>. It is also possible to log
351         one or more parts of the request line independently. For
352         example, the format string "<code>%m %U%q %H</code>" will log
353         the method, path, query-string, and protocol, resulting in
354         exactly the same output as "<code>%r</code>".</dd>
355
356         <dt><code>200</code> (<code>%&gt;s</code>)</dt>
357
358         <dd>This is the status code that the server sends back to the
359         client. This information is very valuable, because it reveals
360         whether the request resulted in a successful response (codes
361         beginning in 2), a redirection (codes beginning in 3), an
362         error caused by the client (codes beginning in 4), or an
363         error in the server (codes beginning in 5). The full list of
364         possible status codes can be found in the <a
365         href="http://www.w3.org/Protocols/rfc2616/rfc2616.txt">HTTP
366         specification</a> (RFC2616 section 10).</dd>
367
368         <dt><code>2326</code> (<code>%b</code>)</dt>
369
370         <dd>The last part indicates the size of the object returned
371         to the client, not including the response headers. If no
372         content was returned to the client, this value will be
373         "<code>-</code>". To log "<code>0</code>" for no content, use
374         <code>%B</code> instead.</dd>
375       </dl>
376     </section>
377
378     <section id="combined">
379       <title>Combined Log Format</title>
380
381       <p>Another commonly used format string is called the Combined
382       Log Format. It can be used as follows.</p>
383
384       <highlight language="config">
385 LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
386 CustomLog "log/access_log" combined
387       </highlight>
388
389       <p>This format is exactly the same as the Common Log Format,
390       with the addition of two more fields. Each of the additional
391       fields uses the percent-directive
392       <code>%{<em>header</em>}i</code>, where <em>header</em> can be
393       any HTTP request header. The access log under this format will
394       look like:</p>
395
396       <example>
397         127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET
398         /apache_pb.gif HTTP/1.0" 200 2326
399         "http://www.example.com/start.html" "Mozilla/4.08 [en]
400         (Win98; I ;Nav)"
401       </example>
402
403       <p>The additional fields are:</p>
404
405       <dl>
406         <dt><code>"http://www.example.com/start.html"</code>
407         (<code>\"%{Referer}i\"</code>)</dt>
408
409         <dd>The "Referer" (sic) HTTP request header. This gives the
410         site that the client reports having been referred from. (This
411         should be the page that links to or includes
412         <code>/apache_pb.gif</code>).</dd>
413
414         <dt><code>"Mozilla/4.08 [en] (Win98; I ;Nav)"</code>
415         (<code>\"%{User-agent}i\"</code>)</dt>
416
417         <dd>The User-Agent HTTP request header. This is the
418         identifying information that the client browser reports about
419         itself.</dd>
420       </dl>
421     </section>
422
423     <section id="multiple">
424       <title>Multiple Access Logs</title>
425
426       <p>Multiple access logs can be created simply by specifying
427       multiple <directive module="mod_log_config">CustomLog</directive>
428       directives in the configuration
429       file. For example, the following directives will create three
430       access logs. The first contains the basic CLF information,
431       while the second and third contain referer and browser
432       information. The last two <directive
433       module="mod_log_config">CustomLog</directive> lines show how
434       to mimic the effects of the <code>ReferLog</code> and <code
435       >AgentLog</code> directives.</p>
436
437       <highlight language="config">
438 LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
439 CustomLog "logs/access_log" common
440 CustomLog "logs/referer_log" "%{Referer}i -&gt; %U"
441 CustomLog "logs/agent_log" "%{User-agent}i"
442       </highlight>
443
444       <p>This example also shows that it is not necessary to define a
445       nickname with the <directive
446       module="mod_log_config">LogFormat</directive> directive. Instead,
447       the log format can be specified directly in the <directive
448       module="mod_log_config">CustomLog</directive> directive.</p>
449     </section>
450
451     <section id="conditional">
452       <title>Conditional Logs</title>
453
454       <p>There are times when it is convenient to exclude certain
455       entries from the access logs based on characteristics of the
456       client request. This is easily accomplished with the help of <a
457       href="env.html">environment variables</a>. First, an
458       environment variable must be set to indicate that the request
459       meets certain conditions. This is usually accomplished with
460       <directive module="mod_setenvif">SetEnvIf</directive>. Then the
461       <code>env=</code> clause of the <directive
462       module="mod_log_config">CustomLog</directive> directive is used to
463       include or exclude requests where the environment variable is
464       set. Some examples:</p>
465
466       <highlight language="config">
467 # Mark requests from the loop-back interface
468 SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
469 # Mark requests for the robots.txt file
470 SetEnvIf Request_URI "^/robots\.txt$" dontlog
471 # Log what remains
472 CustomLog "logs/access_log" common env=!dontlog
473       </highlight>
474
475       <p>As another example, consider logging requests from
476       english-speakers to one log file, and non-english speakers to a
477       different log file.</p>
478
479       <highlight language="config">
480 SetEnvIf Accept-Language "en" english<br />
481 CustomLog "logs/english_log" common env=english<br />
482 CustomLog "logs/non_english_log" common env=!english
483       </highlight>
484
485       <p>In a caching scenario one would want to know about
486       the efficiency of the cache. A very simple method to
487       find this out would be:</p>
488
489       <highlight language="config">
490 SetEnv CACHE_MISS 1
491 LogFormat "%h %l %u %t "%r " %>s %b %{CACHE_MISS}e" common-cache
492 CustomLog "logs/access_log" common-cache
493       </highlight>
494
495       <p><module>mod_cache</module> will run before
496       <module>mod_env</module> and, when successful, will deliver the
497       content without it. In that case a cache hit will log
498       <code>-</code>, while a cache miss will log <code>1</code>.</p>
499
500       <p>In addition to the <code>env=</code> syntax, <directive
501       module="mod_log_config">LogFormat</directive> supports logging values
502       conditional upon the HTTP response code:</p>
503
504       <highlight language="config">
505 LogFormat "%400,501{User-agent}i" browserlog
506 LogFormat "%!200,304,302{Referer}i" refererlog
507       </highlight>
508
509       <p>In the first example, the <code>User-agent</code> will be
510       logged if the HTTP status code is 400 or 501. In other cases, a
511       literal "-" will be logged instead. Likewise, in the second
512       example, the <code>Referer</code> will be logged if the HTTP
513       status code is <strong>not</strong> 200, 204, or 302. (Note the
514       "!" before the status codes.</p>
515
516       <p>Although we have just shown that conditional logging is very
517       powerful and flexible, it is not the only way to control the
518       contents of the logs. Log files are more useful when they
519       contain a complete record of server activity. It is often
520       easier to simply post-process the log files to remove requests
521       that you do not want to consider.</p>
522     </section>
523   </section>
524
525   <section id="rotation">
526     <title>Log Rotation</title>
527
528     <p>On even a moderately busy server, the quantity of
529     information stored in the log files is very large. The access
530     log file typically grows 1 MB or more per 10,000 requests. It
531     will consequently be necessary to periodically rotate the log
532     files by moving or deleting the existing logs. This cannot be
533     done while the server is running, because Apache httpd will continue
534     writing to the old log file as long as it holds the file open.
535     Instead, the server must be <a
536     href="stopping.html">restarted</a> after the log files are
537     moved or deleted so that it will open new log files.</p>
538
539     <p>By using a <em>graceful</em> restart, the server can be
540     instructed to open new log files without losing any existing or
541     pending connections from clients. However, in order to
542     accomplish this, the server must continue to write to the old
543     log files while it finishes serving old requests. It is
544     therefore necessary to wait for some time after the restart
545     before doing any processing on the log files. A typical
546     scenario that simply rotates the logs and compresses the old
547     logs to save space is:</p>
548
549     <example>
550       mv access_log access_log.old<br />
551       mv error_log error_log.old<br />
552       apachectl graceful<br />
553       sleep 600<br />
554       gzip access_log.old error_log.old
555     </example>
556
557     <p>Another way to perform log rotation is using <a
558     href="#piped">piped logs</a> as discussed in the next
559     section.</p>
560   </section>
561
562   <section id="piped">
563     <title>Piped Logs</title>
564
565     <p>Apache httpd is capable of writing error and access log
566     files through a pipe to another process, rather than directly
567     to a file. This capability dramatically increases the
568     flexibility of logging, without adding code to the main server.
569     In order to write logs to a pipe, simply replace the filename
570     with the pipe character "<code>|</code>", followed by the name
571     of the executable which should accept log entries on its
572     standard input. The server will start the piped-log process when
573     the server starts, and will restart it if it crashes while the
574     server is running. (This last feature is why we can refer to
575     this technique as "reliable piped logging".)</p>
576
577     <p>Piped log processes are spawned by the parent Apache httpd
578     process, and inherit the userid of that process. This means
579     that piped log programs usually run as root. It is therefore
580     very important to keep the programs simple and secure.</p>
581
582     <p>One important use of piped logs is to allow log rotation
583     without having to restart the server. The Apache HTTP Server
584     includes a simple program called <program>rotatelogs</program>
585     for this purpose. For example, to rotate the logs every 24 hours, you
586     can use:</p>
587
588     <highlight language="config">
589 CustomLog "|/usr/local/apache/bin/rotatelogs /var/log/access_log 86400" common
590     </highlight>
591
592     <p>Notice that quotes are used to enclose the entire command
593     that will be called for the pipe. Although these examples are
594     for the access log, the same technique can be used for the
595     error log.</p>
596
597     <p>As with conditional logging, piped logs are a very powerful
598     tool, but they should not be used where a simpler solution like
599     off-line post-processing is available.</p>
600
601     <p>By default the piped log process is spawned without invoking
602     a shell. Use "<code>|$</code>" instead of "<code>|</code>"
603     to spawn using a shell (usually with <code>/bin/sh -c</code>):</p>
604
605     <highlight language="config">
606 # Invoke "rotatelogs" using a shell
607 CustomLog "|$/usr/local/apache/bin/rotatelogs   /var/log/access_log 86400" common
608     </highlight>
609
610     <p>This was the default behaviour for Apache 2.2.
611     Depending on the shell specifics this might lead to
612     an additional shell process for the lifetime of the logging
613     pipe program and signal handling problems during restart.
614     For compatibility reasons with Apache 2.2 the notation
615     "<code>||</code>" is also supported and equivalent to using
616     "<code>|</code>".</p>
617
618     <note><title>Windows note</title>
619     <p>Note that on Windows, you may run into problems when running many piped
620     logger processes, especially when HTTPD is running as a service. This is
621     caused by running out of desktop heap space. The desktop heap space given
622     to each service is specified by the third argument to the
623     <code>SharedSection</code> parameter in the
624     HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SessionManager\SubSystems\Windows
625     registry value. <strong>Change this value with care</strong>; the normal
626     caveats for changing the Windows registry apply, but you might also exhaust
627     the desktop heap pool if the number is adjusted too high.</p>
628     </note>
629   </section>
630
631   <section id="virtualhost">
632     <title>Virtual Hosts</title>
633
634     <p>When running a server with many <a href="vhosts/">virtual
635     hosts</a>, there are several options for dealing with log
636     files. First, it is possible to use logs exactly as in a
637     single-host server. Simply by placing the logging directives
638     outside the <directive module="core"
639     type="section">VirtualHost</directive> sections in the
640     main server context, it is possible to log all requests in the
641     same access log and error log. This technique does not allow
642     for easy collection of statistics on individual virtual
643     hosts.</p>
644
645     <p>If <directive module="mod_log_config">CustomLog</directive>
646     or <directive module="core">ErrorLog</directive>
647     directives are placed inside a
648     <directive module="core" type="section">VirtualHost</directive>
649     section, all requests or errors for that virtual host will be
650     logged only to the specified file. Any virtual host which does
651     not have logging directives will still have its requests sent
652     to the main server logs. This technique is very useful for a
653     small number of virtual hosts, but if the number of hosts is
654     very large, it can be complicated to manage. In addition, it
655     can often create problems with <a
656     href="vhosts/fd-limits.html">insufficient file
657     descriptors</a>.</p>
658
659     <p>For the access log, there is a very good compromise. By
660     adding information on the virtual host to the log format
661     string, it is possible to log all hosts to the same log, and
662     later split the log into individual files. For example,
663     consider the following directives.</p>
664
665     <highlight language="config">
666 LogFormat "%v %l %u %t \"%r\" %&gt;s %b" comonvhost
667 CustomLog "logs/access_log" comonvhost
668     </highlight>
669
670     <p>The <code>%v</code> is used to log the name of the virtual
671     host that is serving the request. Then a program like <a
672     href="programs/split-logfile.html">split-logfile</a> can be used to
673     post-process the access log in order to split it into one file
674     per virtual host.</p>
675   </section>
676
677   <section id="other">
678     <title>Other Log Files</title>
679
680     <related>
681       <modulelist>
682         <module>mod_logio</module>
683         <module>mod_log_config</module>
684         <module>mod_log_forensic</module>
685         <module>mod_cgi</module>
686       </modulelist>
687
688       <directivelist>
689         <directive module="mod_log_config">LogFormat</directive>
690         <directive module="mod_log_config">BufferedLogs</directive>
691         <directive module="mod_log_forensic">ForensicLog</directive>
692         <directive module="mpm_common">PidFile</directive>
693         <directive module="mod_cgi">ScriptLog</directive>
694         <directive module="mod_cgi">ScriptLogBuffer</directive>
695         <directive module="mod_cgi">ScriptLogLength</directive>
696       </directivelist>
697     </related>
698
699     <section>
700       <title>Logging actual bytes sent and received</title>
701
702       <p><module>mod_logio</module> adds in two additional
703          <directive module="mod_log_config">LogFormat</directive> fields
704          (%I and %O) that log the actual number of bytes received and sent
705          on the network.</p>
706     </section>
707
708     <section>
709       <title>Forensic Logging</title>
710
711       <p><module>mod_log_forensic</module> provides for forensic logging of
712          client requests. Logging is done before and after processing a
713          request, so the forensic log contains two log lines for each
714          request. The forensic logger is very strict with no customizations.
715          It can be an invaluable debugging and security tool.</p>
716     </section>
717
718     <section id="pidfile">
719       <title>PID File</title>
720
721       <p>On startup, Apache httpd saves the process id of the parent
722       httpd process to the file <code>logs/httpd.pid</code>. This
723       filename can be changed with the <directive
724       module="mpm_common">PidFile</directive> directive. The
725       process-id is for use by the administrator in restarting and
726       terminating the daemon by sending signals to the parent
727       process; on Windows, use the -k command line option instead.
728       For more information see the <a href="stopping.html">Stopping
729       and Restarting</a> page.</p>
730     </section>
731
732     <section id="scriptlog">
733       <title>Script Log</title>
734
735       <p>In order to aid in debugging, the
736       <directive module="mod_cgi">ScriptLog</directive> directive
737       allows you to record the input to and output from CGI scripts.
738       This should only be used in testing - not for live servers.
739       More information is available in the <a
740       href="mod/mod_cgi.html">mod_cgi</a> documentation.</p>
741     </section>
742
743   </section>
744 </manualpage>
745
746
747
748