How to customize local access log that records all incoming http hits
You can ask the tomcat server to log all http requests urls along with parameters that it receives. Apart from this a few other details like client ip, timestamp, response time, response content length etc.
The file $TOMCAT_DIR/conf/server.xml has a Valve element with the className attribute org.apache.catalina.valves.AccessLogValve. This is used to configure access logs.
By default, it is commented out (). To enable access logs, uncomment it. The directory attribute specifies the folder name inside $TOMCAT_DIR where the logs file will be created. Attributes prefix and suffix are the prefix and suffix of log file name respectively.
The 'resolveHost' attribute specifies whether tomcayt should try to get the host name of the client (via dns look up) or just log ip. Unless unavoidable, set it to 'false' to avoid dns look ups which can introduce latency.
The most interesting attribute is pattern. This specifies the tokens that will be stored in access log file for each request. Its default value common stands for '%h %l %u %t "%r" %s %b', which can be used directly as attribute value instead of shorthand 'common'. Other supported tokens are :
The file $TOMCAT_DIR/conf/server.xml has a Valve element with the className attribute org.apache.catalina.valves.AccessLogValve. This is used to configure access logs.
By default, it is commented out (). To enable access logs, uncomment it. The directory attribute specifies the folder name inside $TOMCAT_DIR where the logs file will be created. Attributes prefix and suffix are the prefix and suffix of log file name respectively.
The 'resolveHost' attribute specifies whether tomcayt should try to get the host name of the client (via dns look up) or just log ip. Unless unavoidable, set it to 'false' to avoid dns look ups which can introduce latency.
The most interesting attribute is pattern. This specifies the tokens that will be stored in access log file for each request. Its default value common stands for '%h %l %u %t "%r" %s %b', which can be used directly as attribute value instead of shorthand 'common'. Other supported tokens are :
Token | What it stands for |
---|---|
%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 |
%S | User session ID |
%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 |
%D | Time taken to process the request, in millis |
%T | Time taken to process the request, in seconds |
%I | current request thread name (can compare later with stacktraces) |