1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.core.status;
11
12 import java.util.Iterator;
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15
16 import ch.qos.logback.core.status.Status;
17 import ch.qos.logback.core.status.StatusManager;
18
19 public class StatusChecker {
20
21 StatusManager sm;
22
23 public StatusChecker(StatusManager sm) {
24 this.sm = sm;
25 }
26
27 public boolean containsMatch(String regex) {
28
29 Pattern p = Pattern.compile(regex);
30
31 Iterator stati = sm.getCopyOfStatusList().iterator();
32 while (stati.hasNext()) {
33 Status status = (Status) stati.next();
34 String msg = status.getMessage();
35 Matcher matcher = p.matcher(msg);
36 if (matcher.lookingAt()) {
37 return true;
38 } else {
39 System.out.println("no match:" + msg);
40 System.out.println("regex :" + regex);
41 }
42 }
43 return false;
44 }
45
46 public boolean containsException(Class exceptionType) {
47 Iterator stati = sm.getCopyOfStatusList().iterator();
48 while (stati.hasNext()) {
49 Status status = (Status) stati.next();
50 Throwable t = status.getThrowable();
51 if (t != null && t.getClass().getName().equals(exceptionType.getName())) {
52 return true;
53 }
54 }
55 return false;
56 }
57
58 }