83001520885b5e5f6181de22198d8f0004935465
[mediacube.git] /
1 package hu.user.mediacube.integration.safedelete.logging;
2
3 import ch.qos.logback.classic.spi.ILoggingEvent;
4 import ch.qos.logback.core.filter.AbstractMatcherFilter;
5 import ch.qos.logback.core.spi.FilterReply;
6 import org.apache.logging.log4j.Marker;
7 import org.apache.logging.log4j.MarkerManager;
8
9 /**
10  * @author yoshiori_shoji
11  */
12 public class MarkerFilter extends AbstractMatcherFilter<ILoggingEvent> {
13
14     Marker markerToMatch;
15
16     /*
17      * (non-Javadoc)
18      *
19      * @see ch.qos.logback.core.filter.Filter#decide(java.lang.Object)
20      */
21     @Override
22     public FilterReply decide(ILoggingEvent event) {
23         if (!isStarted()) {
24             return FilterReply.NEUTRAL;
25         }
26         org.slf4j.Marker marker = event.getMarker();
27         if (marker == null) {
28             return onMismatch;
29         }
30
31         if (markerToMatch.toString().equals(marker.toString())) {
32             return onMatch;
33         } else {
34             return onMismatch;
35         }
36     }
37
38     /**
39      * The marker to match in the event.
40      *
41      * @param markerToMatch
42      */
43     public void setMarker(String markerStr) {
44         markerToMatch = MarkerManager.getMarker(markerStr);
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see ch.qos.logback.core.filter.Filter#start()
51      */
52     @Override
53     public void start() {
54         if (this.markerToMatch != null) {
55             super.start();
56         }
57     }
58 }