Reputation: 91
I want to set the Logger for just the /health actuator endpoint to OFF in the application.properties file. Application is on Spring Boot 1.5. The /health would be our new monitoring url for the F5. I don't want to flood the logs. I have this.
logging.level.org.springframework.web=DEBUG
org.springframework.boot.actuate.health.Logger=OFF
logging.level.org.springframework.boot.actuate.health=OFF
I'm still getting DEBUG logging in the console and the log file. The only thing that works is setting the first one to INFO or higher. But, that is not desirable. So, right now i'm getting 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
Do i need to set a different logger property? For a different class/package?
Upvotes: 7
Views: 9571
Reputation: 537
I use logback, so I added a logging filter for this. You need to change the regexes to match your own logging format.
package eu.stackoverflow.logging;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
public class IgnoringHealthAndPrometheusLoggingFilter extends Filter<ILoggingEvent> {
private static final Pattern HEALTH_OR_PROMETHEUS =
Pattern.compile("GET \"/(health|prometheus)\", parameters=\\{}");
private static final Pattern COMPLETED =
Pattern.compile("Completed 200 OK");
private Set<String> activeThreads = new HashSet<>();
@Override
public FilterReply decide(ILoggingEvent loggingEvent) {
if (isHealthOrPrometheus(loggingEvent.getMessage())) {
activeThreads.add(loggingEvent.getThreadName());
return FilterReply.DENY;
} else if (isCompleted200Ok(loggingEvent.getMessage()) && activeThreads.remove(loggingEvent.getThreadName())) {
return FilterReply.DENY;
} else {
return FilterReply.ACCEPT;
}
}
private boolean isHealthOrPrometheus(String message) {
return HEALTH_OR_PROMETHEUS.matcher(message).matches();
}
private boolean isCompleted200Ok(String message) {
return COMPLETED.matcher(message).matches();
}
}
<appender class="ch.qos.logback.core.ConsoleAppender" name="CONSOLE">
<filter class="eu.stackoverflow.logging.IgnoringHealthAndPrometheusLoggingFilter" />
</appender>
More info on logback filters: https://logback.qos.ch/manual/filters.html
Upvotes: 5