title: Tomcat request logging - how to?
body: <p>Env: Tomcat 7.</p>
  
  <p>Would like to log http requests and their headers. Actually I could do without the headers as long as I can log the IP address of the caller, the resource he's requesting (the URL) and the type of request (GET, POST, etc)</p>
  
  <p>This may seem like a trivial question, but it really isn't.</p>
  
  <p>The standard way would be to use the <a href="http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/AccessLogValve.html" rel="nofollow">AccessLogValve</a>, but as far as I understand that one is actually not request logging, it is request/response logging, meaning that it will not log anything before at the end of the response cycle. It will only log those requests where a response has successfully been delivered to the http client. If something goes wrong before that AccessLogValve will <strong>not</strong> log the request.</p>
  
  <p>Question 1:  Is this correctly understood?</p>
  
  <p>Question 2:  Are there other options?</p>
  
  <h3>UPDATE 1:</h3>
  
  <p>I've done a test with Tomcat7 using a dummy-servlet that does blocking for x seconds based on an URL parameter. My findings are that indeed that request gets logged by the AccessLogValve ... although as expected this does not happen until the end of the response, i.e. after the x seconds. There will be a log entry regardless if the client has aborted before the request finishes and regardless if the servlet throws an exception during processing. </p>
  
  <p>Therefore the answer to question 1 is : "No".</p>
  
  <h3>Conclusion</h3>
  
  <p>AcccesLogValve <em>will</em> eventually produce a log entry. At least I haven't been able to produce a scenario where this is <em>not</em> the case.</p>