apache tutorial - Apache Log Format - apache - apache web server - apache server - apache2



  • Apache logs provide detailed information that help to detect common issues with server.
  • In order create access logs, mod_log_configmodule must be enabled.

Three directives available in apache config 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.
<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/accesslog

  CustomLog /usr/www/example/httpd/logs/accesslog combined

</VirtualHost>
click below button to copy the code. By Apache tutorial team

Two types of Apache Log Format

  • 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

LogFormat "%h %l %u %t \"%r\" %>s %b" common

CustomLog logs/access_log common
click below button to copy the code. By Apache tutorial team

Common Log generated by Apache

[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test
click below button to copy the code. By Apache tutorial team

Combined Log Format

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined

CustomLog log/access_log combined
click below button to copy the code. By Apache tutorial team
  • 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:

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)"
click below button to copy the code. By Apache tutorial team
  • 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.
 apache log format

Learn Apache - Apache tutorial - apache log format - Apache examples - Apache programs


Related Searches to Apache Log Format