1
2
3
4
5
6
7
8
9
10
11 package psiprobe.tools.logging.commons;
12
13 import psiprobe.tools.Instruments;
14 import psiprobe.tools.logging.DefaultAccessor;
15 import psiprobe.tools.logging.jdk.Jdk14LoggerAccessor;
16 import psiprobe.tools.logging.log4j.Log4JLoggerAccessor;
17
18
19
20
21 public abstract class AbstractLoggerAccessorVisitor extends DefaultAccessor {
22
23
24
25
26 public void visit() {
27 Object logger = Instruments.getField(getTarget(), "logger");
28 if (logger != null) {
29 if ("org.apache.log4j.Logger".equals(logger.getClass().getName())) {
30 Object level = Instruments.getField(logger, "level");
31 if (level == null) {
32
33 return;
34 }
35 while (logger != null) {
36 Log4JLoggerAccessor accessor = new Log4JLoggerAccessor();
37 accessor.setTarget(logger);
38 accessor.setApplication(getApplication());
39 accessor.setContext(true);
40 visit(accessor);
41 logger = invokeMethod(logger, "getParent", null, null);
42 }
43 } else if ("java.util.logging.Logger".equals(logger.getClass().getName())) {
44 while (logger != null) {
45 Jdk14LoggerAccessor accessor = new Jdk14LoggerAccessor();
46 accessor.setTarget(logger);
47 accessor.setApplication(getApplication());
48 accessor.setContext(true);
49 visit(accessor);
50 logger = invokeMethod(logger, "getParent", null, null);
51 }
52 }
53 }
54 }
55
56
57
58
59
60
61 public abstract void visit(Log4JLoggerAccessor accessor);
62
63
64
65
66
67
68 public abstract void visit(Jdk14LoggerAccessor accessor);
69
70 }