1
2
3
4
5
6
7
8
9
10
11 package psiprobe.tools.logging.jdk;
12
13 import org.apache.commons.lang3.reflect.MethodUtils;
14
15 import psiprobe.tools.logging.AbstractLogDestination;
16
17
18
19
20 public class Jdk14HandlerAccessor extends AbstractLogDestination {
21
22
23 private Jdk14LoggerAccessor loggerAccessor;
24
25
26 private String index;
27
28
29
30
31
32
33 public Jdk14LoggerAccessor getLoggerAccessor() {
34 return loggerAccessor;
35 }
36
37
38
39
40
41
42 public void setLoggerAccessor(Jdk14LoggerAccessor loggerAccessor) {
43 this.loggerAccessor = loggerAccessor;
44 }
45
46 @Override
47 public boolean isContext() {
48 return getLoggerAccessor().isContext();
49 }
50
51 @Override
52 public boolean isRoot() {
53 return getLoggerAccessor().isRoot();
54 }
55
56 @Override
57 public String getName() {
58 return getLoggerAccessor().getName();
59 }
60
61 @Override
62 public String getIndex() {
63 return index;
64 }
65
66
67
68
69
70
71 public void setIndex(String index) {
72 this.index = index;
73 }
74
75 @Override
76 public String getLogType() {
77 return "jdk";
78 }
79
80 @Override
81 public String getLevel() {
82 return getLoggerAccessor().getLevel();
83 }
84
85
86
87
88
89
90 public void setLevel(String newLevelStr) {
91 try {
92 Object level = MethodUtils.invokeMethod(getTarget(), "getLevel");
93 Object newLevel = MethodUtils.invokeMethod(level, "parse", newLevelStr);
94 MethodUtils.invokeMethod(getTarget(), "setLevel", newLevel);
95 } catch (Exception e) {
96 logger.error("{}#setLevel('{}') failed", getTarget().getClass().getName(), newLevelStr, e);
97 }
98 }
99
100 @Override
101 public String[] getValidLevels() {
102 return new String[] {"OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST",
103 "ALL"};
104 }
105
106 }