I am writing a web Rest web service using Spring Boot.
I want to log time taken by my webservice to process request. Also I want to log headers,method and URI called.
I have done similar in my jersey web service few months back using ContainerRequestFilter and ContainerResponseFilter filter() method.
Also, AOP is Better or Filter?
If your controller is Async use Aspect to get the correct and complete execution time.
Add @EnableAspectJAutoProxy to your Applciation Class
And your build.gradle will need the following
Maybe you can use log4j and configure the log to DEBUG
Have you tried with a basic filter like this?
Answer by David is correct - filter is a good way to implement such functionality in Spring Boot.
Spring Boot has a built-in endpoint which returns the information about last 100 requests like shown below:
If your application is calling another services or querying the database consider using Sniffy for profiling - it will show you not only time spent on your server but also time spent in calling downstream systems. See a live demo here (Check the black widget in top bottom corner).
Disclaimer: I'm the author of Sniffy
Spring boot :logging interceptor
register interceptor :