diff --git a/springboot/IgnoringActuatorLoggingFilter.java b/springboot/IgnoringActuatorLoggingFilter.java new file mode 100644 index 0000000..4162979 --- /dev/null +++ b/springboot/IgnoringActuatorLoggingFilter.java @@ -0,0 +1,38 @@ +package me.bvn13.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 IgnoringActuatorLoggingFilter extends Filter { + private static final Pattern ACTUATOR = + Pattern.compile("GET \"/(health|prometheus)\", parameters=\\{}"); + private static final Pattern COMPLETED = + Pattern.compile("Completed 200 OK"); + + private final Set 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 ACTUATOR.matcher(message).matches(); + } + + private boolean isCompleted200Ok(String message) { + return COMPLETED.matcher(message).matches(); + } +} diff --git a/springboot/logback-prod.xml b/springboot/logback-prod.xml new file mode 100644 index 0000000..d633115 --- /dev/null +++ b/springboot/logback-prod.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/springboot.yaml b/springboot/springboot.yaml similarity index 100% rename from springboot.yaml rename to springboot/springboot.yaml