1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.turbo;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.slf4j.MDC;
20 import org.slf4j.Marker;
21
22 import ch.qos.logback.classic.ClassicConstants;
23 import ch.qos.logback.classic.Level;
24 import ch.qos.logback.classic.Logger;
25 import ch.qos.logback.core.spi.FilterReply;
26
27
28
29
30
31
32
33
34
35
36
37
38 public class DebugUsersTurboFilter extends TurboFilter {
39
40 List<String> userList = new ArrayList<String>();
41
42 @Override
43 public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
44 if (!level.equals(Level.DEBUG)) {
45 return FilterReply.NEUTRAL;
46 }
47 String user = MDC.get(ClassicConstants.USER_MDC_KEY);
48 if (user != null && userList.contains(user)) {
49 return FilterReply.ACCEPT;
50 }
51 return FilterReply.NEUTRAL;
52 }
53
54 public void addUser(String user) {
55 userList.add(user);
56 }
57
58
59 public List<String> getUsers() {
60 return userList;
61 }
62
63 }