Specify the kind of information written in the tomcat access log files

Log files are written by the Tomcat valve AccessLogValve. A valve, Tomcat only, is a Java class that preprocesses access requests. You can associate valves in server.xml to the containers engine, host and context.

Possible attributes for the AccessLogValve are the following.

  • directory: the directory to where the log files are written, can be relative to CATALINA_HOME or absolute, default value: logs

  • pattern: specifies what type of infomration a log line should contain. You can combine any of the following patterns:
    %a - Remote IP address 
    %A - Local IP address 
    %b - Bytes sent, excluding HTTP headers, or '-' if zero 
    %B - Bytes sent, excluding HTTP headers 
    %h - Remote host name (or IP address if resolveHosts is false) 
    %H - Request protocol 
    %l - Remote logical username from identd (always returns '-') 
    %m - Request method (GET, POST, etc.) 
    %p - Local port on which this request was received 
    %q - Query string (prepended with a '?' if it exists) 
    %r - First line of the request (method and request URI) 
    %s - HTTP status code of the response 
    %t - Date and time, in Common Log Format 
    %u - Remote user that was authenticated (if any), else '-' 
    %U - Requested URL path 
    %v - Local server name 
    

    Specifying common is the same as specifying %h %l %u %t “%r” %s %b.
    For example:
    With pattern common:

    127.0.0.1 - - [21/Jul/2002:20:16:31 -0800] "GET /index.html HTTP/1.1" 200 6827
    127.0.0.1 - - [21/Jul/2002:20:16:31 -0800] "GET /tomcat.gif HTTP/1.1" 200 1934
    127.0.0.1 - - [21/Jul/2002:20:16:31 -0800] "GET /jakarta-banner.gif HTTP/1.1" 304 -
    127.0.0.1 - - [21/Jul/2002:20:16:32 -0800] "GET /tomcat-power.gif HTTP/1.1" 304 -
    

    With pattern Request from %a: %r:

    Request from 127.0.0.1: GET /index.html HTTP/1.1
    Request from 127.0.0.1: GET /tomcat.gif HTTP/1.1
    Request from 127.0.0.1: GET /jakarta-banner.gif HTTP/1.1
    Request from 127.0.0.1: GET /tomcat-power.gif HTTP/1.1
    
  • prefix: a string that should be added to the start of each log filename, default value: access_log
  • suffix: a string that should be added to the end of each log filename, default value: empty
  • resolveHosts: a boolean value, if set to true, it will look up the corresponding host name for the requesting IP address. Use it only if absolutely necessary, it will slow down Tomcat a lot.