1 package ch.qos.logback.core.filter;
2
3 import ch.qos.logback.core.boolex.EvaluationException;
4 import ch.qos.logback.core.boolex.EventEvaluator;
5 import ch.qos.logback.core.spi.FilterReply;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public class EvaluatorFilter<E> extends AbstractMatcherFilter<E> {
25
26 EventEvaluator<E> evaluator;
27
28 @Override
29 public void start() {
30 if (evaluator != null) {
31 super.start();
32 } else {
33 addError("No evaluator set for filter " + this.getName());
34 }
35 }
36
37 public EventEvaluator<E> getEvaluator() {
38 return evaluator;
39 }
40
41 public void setEvaluator(EventEvaluator<E> evaluator) {
42 this.evaluator = evaluator;
43 }
44
45 public FilterReply decide(E event) {
46
47
48 if (!isStarted() || !evaluator.isStarted()) {
49 return FilterReply.NEUTRAL;
50 }
51 try {
52 if (evaluator.evaluate(event)) {
53 return onMatch;
54 } else {
55 return onMismatch;
56 }
57 } catch (EvaluationException e) {
58 addError("Evaluator " + evaluator.getName() + " threw an exception", e);
59 return FilterReply.NEUTRAL;
60 }
61 }
62
63 }