Skip to content

Instantly share code, notes, and snippets.

@yoshiori
Created October 21, 2011 10:37
Show Gist options
  • Save yoshiori/1303543 to your computer and use it in GitHub Desktop.
Save yoshiori/1303543 to your computer and use it in GitHub Desktop.
/**
*
*/
package org.yoshiori.logback.filter;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;
/**
* @author yoshiori_shoji
*
*/
public class MarkerFilter extends AbstractMatcherFilter<ILoggingEvent> {
Marker markerToMatch;
/*
* (non-Javadoc)
*
* @see ch.qos.logback.core.filter.Filter#decide(java.lang.Object)
*/
@Override
public FilterReply decide(ILoggingEvent event) {
if (!isStarted()) {
return FilterReply.NEUTRAL;
}
Marker marker = event.getMarker();
if (marker == null) {
return onMismatch;
}
if (markerToMatch.contains(marker)) {
return onMatch;
} else {
return onMismatch;
}
}
/**
* The marker to match in the event.
*
* @param markerToMatch
*/
public void setMarker(String markerStr) {
if (markerStr != null) {
this.markerToMatch = MarkerFactory.getMarker(markerStr);
}
}
/*
* (non-Javadoc)
*
* @see ch.qos.logback.core.filter.Filter#start()
*/
@Override
public void start() {
if (this.markerToMatch != null) {
super.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment