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