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 @SuppressWarnings("rawtypes")
42 public static Stack cloneStack() {
43 return null;
44 }
45
46 @SuppressWarnings("rawtypes")
47 public static void inherit(Stack stack) {
48 }
49
50 static public String get() {
51 return null;
52 }
53
54 public static int getDepth() {
55 int i = 0;
56 while (true) {
57 String val = MDC.get(PREFIX + i);
58 if (val != null) {
59 i++;
60 } else {
61 break;
62 }
63 }
64 return i;
65 }
66
67 public static String pop() {
68 int next = getDepth();
69 if (next == 0) {
70 return "";
71 }
72 int last = next - 1;
73 String key = PREFIX + last;
74 String val = MDC.get(key);
75 MDC.remove(key);
76 return val;
77 }
78
79 public static String peek() {
80 int next = getDepth();
81 if (next == 0) {
82 return "";
83 }
84 int last = next - 1;
85 String key = PREFIX + last;
86 String val = MDC.get(key);
87 return val;
88 }
89
90 public static void push(String message) {
91 int next = getDepth();
92 MDC.put(PREFIX + next, message);
93 }
94
95 static public void remove() {
96 clear();
97 }
98
99 static public void setMaxDepth(int maxDepth) {
100 }
101
102 }