Apache httpd provides various logging mechanisms. The most common are the access log and the error log. Logging configuration is slightly different between 2.2 and 2.4.
The error log is configured with the ErrorLog and LogLevel directives. ErrorLog may be defined globally, or per virtualhost.
The ErrorLog directive specifies a location where the log entries will be written. This can be either a log file location, or a program to which the log entries will be piped.
To specify a log file location:
ErrorLog "/var/log/httpd/error_log"
To specify a pipe that will process the log entries:
ErrorLog "|/usr/local/bin/httpd_errors"
The LogLevel directive sets the verbosity of the logging.
LogLevel may be set globally or per virtualhost in 2.2, and in 2.4 it can additionally be set per directory, or per module, as shown in the examples below.
In 2.2, LogLevel may be set to one of the following values.
Level |
Description |
Example |
emerg |
Emergencies - system is unusable. |
"Child cannot open lock file. Exiting" |
alert |
Action must be taken immediately. |
"getpwuid: couldn't determine user name from uid" |
crit |
Critical Conditions. |
"socket: Failed to get a socket, exiting child" |
error |
Error conditions. |
"Premature end of script headers" |
warn |
Warning conditions. |
"child process 1234 did not exit, sending another SIGHUP" |
notice |
Normal but significant condition. |
"httpd: caught SIGBUS, attempting to dump core in ..." |
info |
Informational. |
"Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)..." |
debug |
Debug-level messages |
"Opening config file ..." |
Each setting includes log entries from higher severities. It is recommended that you set LogLevel to at least crit or error.
ErrorLog error
In 2.4, LogLevel may be set to any of those values, or to one of the following additional values:
Level |
Description |
Example |
trace1 |
Trace messages |
"proxy: FTP: control connection complete" |
trace2 |
Trace messages |
"proxy: CONNECT: sending the CONNECT request to the remote proxy" |
trace3 |
Trace messages |
"openssl: Handshake: start" |
trace4 |
Trace messages |
"read from buffered SSL brigade, mode 0, 17 bytes" |
trace5 |
Trace messages |
"map lookup FAILED: map=rewritemap key=keyname" |
trace6 |
Trace messages |
"cache lookup FAILED, forcing new map lookup" |
trace7 |
Trace messages, dumping large amounts of data |
"| 0000: 02 23 44 30 13 40 ac 34 df 3d bf 9a 19 49 39 15 |" |
trace8 |
Trace messages, dumping large amounts of data |
"| 0000: 02 23 44 30 13 40 ac 34 df 3d bf 9a 19 49 39 15 |" |
In 2.4, ErrorLog may be configured at different levels per module, in case you want more information from a particular module without increasing it on any others:
ErrorLog crit ssl:warn
You can also set ErrorLog in a <Directory> block, which is not possible in 2.2.
The access log, which logs request information, is configured using the LogFormat and CustomLog directives.
LogFormat configures the information that will be put in a log file, and assigns an alias to a particular format. The following line defines the common log file format.
LogFormat "%h %l %u %t \"%r\" %>s %b" common
In the common format, the fields have the following meaning:
Format String |
Meaning |
%h |
Address of client. |
%l |
Remote logname from identd, if supplied. ‘-‘ otherwise. |
%u |
Remote username, if the request was authenticated. ‘-‘ otherwise. |
%t |
The date and time that the request was received. |
%r |
The first line of the request. |
%s |
The HTTP status code of the response. |
%b |
The total number of bytes returned to the client, not including headers. |
Numerous other format strings are available, and are documented at http://httpd.apache.org/docs/current/mod/mod_log_config.html#formats
Once a LogFormat is defined, it can then be used in a CustomLog directive, which may be set on a per-virtualhost basis:
CustomLog "/var/log/httpd/access_log" common
As with ErrorLog, CustomLog may point to the location of a log file, or may specify a program to which the messages will be piped.
Using the 'env=' syntax, CustomLog may specify a conditional environment variable to determine whether the log entry will be made:
SetEnvIf Request_URI \.gif$ gif-image
CustomLog gif-requests.log common env=gif-image
In the example shown here, the specified log file will be written to only if the requested URL has a .gif file extension.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}