Log Files - Apache HTTP Server Version 2.4
Modules | Directives | FAQ | Glossary | Sitemap | Report a bug Apache HTTP Server Version 2.4 Apache > HTTP Server > Documentation > Version 2.4 Log Files Available Languages: en | fr | ja | ko | tr In order to effectively manage a web server, it is necessary to get feedback about the activity and performance of the server as well as any problems that may be occurring. The Apache HTTP Server provides very comprehensive and flexible logging capabilities.
This document describes how to configure its logging capabilities, and how to understand what the logs contain. Overview Security Warning Error Log Per-module logging Access Log Log Rotation Piped Logs Virtual Hosts Other Log Files Overview ¶ Related Modules Related Directives mod_log_config mod_log_forensic mod_logio mod_cgi The Apache HTTP Server provides a variety of different mechanisms for logging everything that happens on your server, from the initial request, through the URL mapping process, to the final resolution of the connection, including any errors that may have occurred in the process.
In addition to this, third-party modules may provide logging capabilities, or inject entries into the existing log files, and applications such as CGI programs, or PHP scripts, or other handlers, may send messages to the server error log. In this document we discuss the logging modules that are a standard part of the http server. Security Warning ¶ Anyone who can write to the directory where Apache httpd is writing a log file can almost certainly gain access to the uid that the server is started as, which is normally root.
Do NOT give people write access to the directory the logs are stored in without being aware of the consequences; see the security tips document for details. In addition, log files may contain information supplied directly by the client, without escaping. Therefore, it is possible for malicious clients to insert control-characters in the log files, so care must be taken in dealing with raw logs. Error Log ¶ Related Modules Related Directives core ErrorLog ErrorLogFormat LogLevel The server error log, whose name and location is set by the ErrorLog directive, is the most important log file.
This is the place where Apache httpd will send diagnostic information and record any errors that it encounters in processing requests. It is the first place to look when a problem occurs with starting the server or with the operation of the server, since it will often contain details of what went wrong and how to fix it. The error log is usually written to a file (typically error_log on Unix systems and error.log on Windows and OS/2).
On Unix systems it is also possible to have the server send errors to syslog or pipe them to a program . The format of the error log is defined by the ErrorLogFormat directive, with which you can customize what values are logged. A default is format defined if you don't specify one. A typical log message follows: [Fri Sep 09 10:42:29.902022 2011] [core:error] [pid 35708:tid 4328636416] [client 72.15.99.187] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error The first item in the log entry is the date and time of the message.
The next is the module producing the message (core, in this case) and the severity level of that message. This is followed by the process ID and, if appropriate, the thread ID, of the process that experienced the condition. Next, we have the client address that made the request. And finally is the detailed error message. Note that some messages that were previously logged at error level have been downgraded to info level in httpd 2.4.
For example, "File does not exist" messages for 404 responses are logged at info level and will not appear in the error log with the default LogLevel of warn . To restore the previous behavior, use LogLevel warn core:info . A very wide variety of different messages can appear in the error log. Most look similar to the example above. The error log will also contain debugging output from CGI scripts. Any information written to stderr by a CGI script will be copied directly to the error log.
Putting a %L token in both the error log and the access log will produce a log entry ID with which you can correlate the entry in the error log with the entry in the access log. If mod_unique_id is loaded, its unique request ID will be used as the log entry ID, too. During testing, it is often useful to continuously monitor the error log for any problems. On Unix systems, you can accomplish this using: tail -f error_log Per-module logging ¶ The LogLevel directive allows you to specify a log severity level on a per-module basis.
In this way, if you are troubleshooting a problem with just one particular module, you can turn up its logging volume without also getting the details of other modules that you're not interested in. This is particularly useful for modules such as mod_proxy or mod_rewrite where you want to know details about what it's trying to do. Do this by specifying the name of the module in your LogLevel directive: LogLevel info rewrite:trace5 This sets the main LogLevel to info, but turns it up to trace5 for mod_rewrite .
This replaces the per-module logging directives, such as RewriteLog , that were present in earlier versions of the server. Access Log ¶ Related Modules Related Directives mod_log_config mod_setenvif CustomLog LogFormat SetEnvIf The server access log records all requests processed by the server. The location and content of the access log are controlled by the CustomLog directive. The LogFormat directive can be used to simplify the selection of the contents of the logs.
This section describes how to configure the server to record information in the access log. Storing the information in the access log is only the start of log management. The next step is to analyze this information to produce useful statistics. Log analysis in general is beyond the scope of this document, and not really part of the job of the web server itself. Various versions of Apache httpd have used other modules and directives to control access logging, including mod_log_referer, mod_log_agent, and the TransferLog directive.
The CustomLog directive now subsumes the functionality of all the older directives. The format of the access log is highly configurable. The format is specified using a format string that looks much like a C-style printf(1) format string. Some examples are presented in the next sections. For a complete list of the possible contents of the format string, see the mod_log_config format strings . Common Log Format A typical configuration for the access log might look as follows.
LogFormat "%h %l %u %t \"%r\" %>s %b" common CustomLog "logs/access_log" common This defines the nickname common and associates it with a particular log format string. The format string consists of percent directives, each of which tell the server to log a particular piece of information. Literal characters may also be placed in the format string and will be copied directly into the log output. The quote character ( " ) must be escaped by placing a backslash before it to prevent it from being interpreted as the end of the format string.
The format string may also contain the special control characters " \n " for new-line and " \t " for tab. The CustomLog directive sets up a new log file using the defined nickname . The filename for the access log is relative to the ServerRoot unless it begins with a slash. The above configuration will write log entries in a format known as the Common Log Format (CLF). This standard format can be produced by many different web servers and read by many log analysis programs.
The log file entries produced in CLF will look something like this: 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 Each part of this log entry is described below. 127.0.0.1 ( %h ) This is the IP address of the client (remote host) which made the request t
The rest of this page is on the live site.