Prevent DispatcherServlet from logging endpoint in Spring Boot Actuator

Viewed 1170

I've turned off the Logging for an actuator endpoint, but DispatcherServlet (and RequestReponseBodyMethodProcessor) still log the mapping and response.

How can i prevent this logging for just this one endpoint? I've already turned them off

management.logging.level.org.springframework.boot.actuate.health=OFF
logging.level.org.springframework.boot.actuate.health=OFF
org.springframework.boot.actuate.health.Logger=OFF

but it still comes like this:

2020-05-06 17:14:01.545 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/health]
2020-05-06 17:14:01.552 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/health] is: -1
2020-05-06 17:14:01.848 DEBUG 58588 --- [nio-9095-exec-5] m.m.a.RequestResponseBodyMethodProcessor : Written [UP {}] as "application/vnd.spring-boot.actuator.v1+json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@144409aa]
2020-05-06 17:14:01.849 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2020-05-06 17:14:01.849 DEBUG 58588 --- [nio-9095-exec-5] o.s.web.servlet.DispatcherServlet        : Successfully completed request

3 Answers

Just set in application.properties log level to WARN

logging.level.org.springframework.web.servlet.DispatcherServlet=WARN
logging.level.org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor=WARN

please check if this solves the issue

In annotation SpringBootApplication add exclude DispatcherServletAutoConfiguration class in main class.

@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })

reference :

Switch off DispatcherServlet on Spring Boot

If your goal is logging all the incoming HTTP requests, the solution is not enabling DEBUG logging level in the DispatcherServlet.

You can define a bean of type:

org.springframework.web.filter.CommonsRequestLoggingFilter

and override the method:

org.springframework.web.filter.CommonsRequestLoggingFilter.shouldLog(HttpServletRequest)

So you can decide which requests are logged or not. Obviously, you must set the logging level of the filter to DEBUG:

logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG

More info at Baeldubg site.

Related