Apache Configuration Guide

Know how to configure Apache server to write logs.

Sample log:

[08/Dec/2020:10:30:17 +0000] Remote-IP= Local-IP= Remote-Host= RemoteLogName=- Remote-User=- Request="GET /docs/ssi-howto.html HTTP/1.1" Status=200 Bytes-Sent=18379 Referer="" User-Agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" URL=/docs/ssi-howto.html Method=GET Protocol=HTTP/1.1 

Log Pattern:

%t           Remote-IP=%a  Local-IP=%A       Remote-Host=%h             RemoteLogName=%l      Remote-User=%u                Request="%r"            Status=%s           Bytes-Sent=%b Referer="%{Referer}i"              User-Agent="%{User-agent}i"       URL=%U              Method=%m      Protocol=%H

To configure Apache server to write logs in below format, the application admin needs to perform given steps:

  1. Locate the “server.xml” file, this is normally located in Apache root directory under “Tomcat x.x\conf” folder.
  2. Open the file and edit element “Valve className="org.apache.catalina.valves.AccessLogValve"” in the file:
  3. Please choose the Absolute or relative directory path for the log file location.
  4. Choose the prefix and suffix for the log files as show in screenshot.
  5. Copy paste the pattern provided log pattern in the pattern field, this field is surrounded by double quotes.

For more information we can refer below link.

Ref: https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html