Apache logs provide detailed information that help to detect common issues with server.
In order create logs, mod_log_configmodule must be enabled.
There are three directives available in apache configuration file i.e.
TransferLog directive is available in the apache configuration file and it rotates virtual host log files as per set parameters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<VirtualHost www.example.com> ServerAdmin webmaster@example.com DocumentRoot /usr/www/example/httpd/htdocs/ ServerName www.example.com ServerAlias example.com www.example ErrorLog /usr/www/example/httpd/logs/error_log TransferLog/usr/www/example/httpd/logs/access_log CustomLog /usr/www/example/httpd/logs/access_log combined </VirtualHost> |
There are two types of LogFormat available with Apache,
You can enable them by editing the apache configuration file i.e. apache2.conf (Debian/ubuntu) or httpd.conf (rpm based systems) file
Common Log Format
1
2
3
|
LogFormat "%h %l %u %t \"%r\" %>s %b" common CustomLog logs/access_log common |
Common Log generated by Apache
1
|
[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test |
Combined Log Format
1
2
3
|
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined CustomLog log/access_log combined |
Here,
Combined Log generated by Apache:
1
|
199.187.122.91 - - [06/Mar/2014:04:22:58 +0100] "GET /robots.txt HTTP/1.1" 404 1228 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" |
Custom Log creates separate log file for each Virtual Host on your server. It needs to be specified in the virtual host section of the config file.
You can see below mentioned virtual host configuration, generated log will be custom for that virtual host and the format will be combined.