1
2
3
4
5
6
7
8
9
10
11 package ch.qos.logback.classic;
12
13 import ch.qos.logback.classic.Level;
14
15
16
17
18
19
20 public class HLoggerContext {
21
22 private HLogger root;
23 private int size;
24
25 public HLoggerContext() {
26 this.root = new HLogger("root", null);
27 this.root.setLevel(Level.DEBUG);
28 size = 1;
29 }
30
31
32
33
34
35
36 public HLogger getRootLogger() {
37 return root;
38 }
39
40 public HLogger getLogger(final String name) {
41
42 int i = 0;
43 HLogger HLogger = root;
44 HLogger childHLogger = null;
45 String childName;
46
47 while (true) {
48 int h = name.indexOf('.', i);
49 if (h == -1) {
50 childName = name.substring(i);
51 } else {
52 childName = name.substring(i, h);
53 }
54
55 i = h + 1;
56
57 synchronized (HLogger) {
58 childHLogger = HLogger.getChildBySuffix(childName);
59 if (childHLogger == null) {
60 childHLogger = HLogger.createChildByLastNamePart(childName);
61 incSize();
62 }
63 }
64 HLogger = childHLogger;
65 if (h == -1) {
66 return childHLogger;
67 }
68 }
69 }
70
71 private synchronized void incSize() {
72 size++;
73 }
74
75 int size() {
76 return size;
77 }
78
79
80
81
82
83
84 HLogger exists(String name) {
85 int i = 0;
86 HLogger HLogger = root;
87 HLogger childHLogger = null;
88 String childName;
89 while (true) {
90 int h = name.indexOf('.', i);
91 if (h == -1) {
92 childName = name.substring(i);
93 } else {
94 childName = name.substring(i, h);
95 }
96
97 i = h + 1;
98
99 synchronized (HLogger) {
100 childHLogger = HLogger.getChildBySuffix(childName);
101 if (childHLogger == null) {
102 return null;
103 }
104 }
105 HLogger = childHLogger;
106 if (h == -1) {
107 if (childHLogger.getName().equals(name)) {
108 return childHLogger;
109 } else {
110 return null;
111 }
112 }
113 }
114 }
115 }