Created
October 21, 2011 10:37
-
-
Save yoshiori/1303543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
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