1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j;
19
20 import org.slf4j.MDC;
21
22 import java.util.Stack;
23
24
25
26
27
28
29
30 public class NDC {
31
32 public final static String PREFIX = "NDC";
33
34 public static void clear() {
35 int depth = getDepth();
36 for (int i = 0; i < depth; i++) {
37 String key = PREFIX + i;
38 MDC.remove(key);
39 }
40 }
41
42 public static Stack cloneStack() {
43 return null;
44 }
45
46 public static void inherit(Stack stack) {
47 }
48
49 static public String get() {
50 return null;
51 }
52
53 public static int getDepth() {
54 int i = 0;
55 while (true) {
56 String val = MDC.get(PREFIX + i);
57 if (val != null) {
58 i++;
59 } else {
60 break;
61 }
62 }
63 return i;
64 }
65
66 public static String pop() {
67 int next = getDepth();
68 if (next == 0) {
69 return "";
70 }
71 int last = next - 1;
72 String key = PREFIX + last;
73 String val = MDC.get(key);
74 MDC.remove(key);
75 return val;
76 }
77
78 public static String peek() {
79 int next = getDepth();
80 if (next == 0) {
81 return "";
82 }
83 int last = next - 1;
84 String key = PREFIX + last;
85 String val = MDC.get(key);
86 return val;
87 }
88
89 public static void push(String message) {
90 int next = getDepth();
91 MDC.put(PREFIX + next, message);
92 }
93
94 static public void remove() {
95 clear();
96 }
97
98 static public void setMaxDepth(int maxDepth) {
99 }
100
101 }