简体   繁体   中英

Spring REST service log request and response messages

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

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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM