0

How to log incoming request and response HTTP messages along with headers for my Spring REST services? I am using Spring 4 and Tomcat 7.

What is the best practice to log the above?

I checked logBack TeeFilter but the documentation advises to disable it in production machine. I am looking to setup something that I can use in production as well. Would like to log the request and response to a specific log file.

I have looked through stack overflow and there are different suggestion so not sure which is the best approach to take as of Spring 4.0

serah
  • 2,057
  • 7
  • 36
  • 56
  • maybe this can help you: http://stackoverflow.com/questions/7952154/spring-resttemplate-how-to-enable-full-debugging-logging-of-requests-responses – Angelo Immediata Oct 10 '16 at 13:45
  • @AngeloImmediata - Is the answer choice chosen by the user in the above post the correct solution.? There are more solutions provided by others below the user's choice as the answer that suggests that its not a good solution. This is what is confusing to me as to what is the right approach to take. – serah Oct 10 '16 at 14:10
  • I am curious of what your approach is eventually. Do you disable the TeeFilter in production? I am facing the same decision to make now :-) – imarchuang Jan 01 '18 at 03:46

1 Answers1

0

I have been using the answer provided in Java/Tomcat standalone, how to log/access all the HTTP GET requests for my Spring 4 project and it works like a charm. Idea behind this is to remove logging from code for http.

Uncomment below in server.xml:

<Valve className="org.apache.catalina.valves.AccessLogValve"
    directory="logs" prefix="localhost_access_log." suffix=".txt"
    pattern="common" resolveHosts="false"/>
Community
  • 1
  • 1
HARDI
  • 394
  • 5
  • 12