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