FAQ

Apache HTTP Server - Configuring the logging capabilities

In order to analyze your log file using LogAnalyzer, your log file should contain the following information: ID, date and time at which transaction completed, result, IP address of the client which made the request to the Web server, URL path requested, bytes sent, user agent, referer, time taken to serve the request, and search arguments. This tutorial will show you, how to configure Apache's logging capabilities.

Before we configure the logging capabilities, we need to know where Apache's configuration file lives. To find out, we will query Apache itself with the following command line:
httpd -V

This will print out information specific to your Apache installation. We find out where the configuration file is located:
SERVER_CONFIG_FILE="/etc/httpd/httpd.conf"

as well as where the access log file for Apache is stored:
DEFAULT_XFERLOG="/var/log/httpd/access_log"

After doing the above, open up your configuration file in your favorite text editor (NOTE: it is always a good idea to back the configuration file up before making any changes). The example below assumes pico, a command line interface (CLI) text editor, which is easy to learn. Another option is to use a text editor capable of opening and editing hidden files like BBEdit, check out our tutorial Mac OS X - Opening and editing hidden files.
sudo pico /etc/httpd/httpd.conf
And this is, what you will see:

The Apache configuration file is rather long, but also well documented. We are looking for something called "LogFormat", which specifies the format of the access log file. To search for "LogFormat", press the control and "V" keys as indicated in the two rows of command promts at the bottom. You should see some lines similar to:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

We will add the following line:
LogFormat "%P\t%{%m/%d/%y}t\t%{%T}t\t%c\t%h\t%U\t%B\t%{User-Agent}i\t%{Referer}i\t%T\t%q" wextor
This directive lists a sequence of field identifiers, each of which tell Apache to log a particular piece of information. Fields are separated by tab characters, indicated by the special control characters "\t".

Next, we do a search for "CustomLog" which specifies the location to which the log file will be written. You should see a line similar to:
CustomLog "/var/log/httpd/access_log" common

We will add the following line:
CustomLog "/var/log/httpd/access_log_wextor" wextor
Once you have made the changes, save the document by pressing the control and "O" keys. You will be prompted to confirm the save. Just press return to do so. Finally, quit pico by pressing the control and "X" keys and restart Apache:
apachectl -k graceful
By adding the above lines, you are telling Apache to set up a new log file "access_log_wextor" and to capture the information indicated above.
[back]