1 package ch.qos.logback.access.common.boolex;
2
3 import ch.qos.logback.access.common.spi.IAccessEvent;
4 import ch.qos.logback.core.boolex.EvaluationException;
5 import ch.qos.logback.core.boolex.EventEvaluatorBase;
6
7
8
9
10
11
12
13
14 public class StatusCodeEventEvaluator extends EventEvaluatorBase<IAccessEvent> {
15
16 final static int UNSET = -1;
17 int statusCode = UNSET;
18
19 @Override
20 public void start() {
21 if(statusCode == UNSET) {
22 addWarn("No status code set");
23 return;
24 }
25 super.start();
26 }
27 @Override
28 public boolean evaluate(IAccessEvent iAccessEvent) throws NullPointerException, EvaluationException {
29 if (!isStarted()) {
30 throw new IllegalStateException("Evaluator [" + this + "] was called in stopped state");
31 }
32 boolean result = (iAccessEvent.getStatusCode() == statusCode);
33 return result;
34 }
35
36 public int getStatusCode() {
37 return statusCode;
38 }
39
40 public void setStatusCode(int statusCode) {
41 this.statusCode = statusCode;
42 }
43 }