preparing springboot

This commit is contained in:
bvn13 2024-09-17 21:54:58 +03:00
parent 7987b383d5
commit a530d52d05
3 changed files with 49 additions and 0 deletions

View File

@ -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<ILoggingEvent> {
private static final Pattern ACTUATOR =
Pattern.compile("GET \"/(health|prometheus)\", parameters=\\{}");
private static final Pattern COMPLETED =
Pattern.compile("Completed 200 OK");
private final 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 ACTUATOR.matcher(message).matches();
}
private boolean isCompleted200Ok(String message) {
return COMPLETED.matcher(message).matches();
}
}

View File

@ -0,0 +1,11 @@
<configuration>
<appender name="JSON_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="me.bvn13.logging.IgnoringActuatorLoggingFilter"/>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<root level="info">
<!-- <appender-ref ref="STDOUT" />-->
<appender-ref ref="JSON_STDOUT"/>
</root>
</configuration>