How to manage Apache Logs ?

Answer

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: Creating a log file.
  • LogFormat : Specifying a custom format.
  • CustomLog : Creating and formatting a log file.

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,

  • Common Log Format
  • Combined Log Format.

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,

  • %h is the remote host
  • %l is the identity of the user determined by identd
  • %u is the user name determined by HTTP authentication
  • %t is the time the server finished processing the request.
  • %r is the request line from the client. ("GET / HTTP/1.0")
  • %>s is the status code sent from the server to the client (500, 404 etc.)
  • %b is the size of the response to the client (in bytes)
  • Referer is the page that linked to this URL.
  • User-agent is the browser identification string.

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.

All apache Questions

Ask your interview questions on apache

Write Your comment or Questions if you want the answers on apache from apache Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---