no.entur.logging.cloud.appender.scope.DefaultLoggingScope Maven / Gradle / Ivy
The newest version!
package no.entur.logging.cloud.appender.scope;
import ch.qos.logback.classic.spi.ILoggingEvent;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Predicate;
/**
* Logging scope for temporarily adjusting what gets logged, caching the log skipped-over log statements in the process.
*
*/
public class DefaultLoggingScope implements LoggingScope {
private final Predicate queuePredicate;
private final Predicate ignorePredicate;
private final Predicate logLevelFailurePredicate;
private boolean logLevelFailure = false;
private ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue();
public DefaultLoggingScope(Predicate queuePredicate, Predicate ignorePredicate, Predicate logLevelFailurePredicate) {
this.queuePredicate = queuePredicate;
this.ignorePredicate = ignorePredicate;
this.logLevelFailurePredicate = logLevelFailurePredicate;
}
public ConcurrentLinkedQueue getEvents() {
return queue;
}
public boolean append(ILoggingEvent eventObject) {
if(ignorePredicate.test(eventObject)) {
return true;
}
if(!logLevelFailure && logLevelFailurePredicate.test(eventObject)) {
logLevelFailure = true;
}
if(queuePredicate.test(eventObject)) {
queue.add(eventObject);
return true;
}
return false;
}
public boolean isLogLevelFailure() {
return logLevelFailure;
}
}