1 /* 2 * Copyright 2001-2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.apache.log4j; 18 19 import java.util.Hashtable; 20 import java.util.Map; 21 22 public class MDC { 23 24 public static void put(String key, String value) { 25 org.slf4j.MDC.put(key, value); 26 } 27 28 public static void put(String key, Object value) { 29 if (value != null) { 30 put(key, value.toString()); 31 } else { 32 put(key, null); 33 } 34 } 35 36 public static Object get(String key) { 37 return org.slf4j.MDC.get(key); 38 } 39 40 public static void remove(String key) { 41 org.slf4j.MDC.remove(key); 42 } 43 44 public static void clear() { 45 org.slf4j.MDC.clear(); 46 } 47 48 /** 49 * This method is not part of the Log4J public API. However it 50 * has been called by other projects. This method is here temporarily 51 * until projects who are depending on this method release fixes. 52 */ 53 @SuppressWarnings({ "rawtypes", "unchecked" }) 54 @Deprecated 55 public static Hashtable getContext() { 56 Map map = org.slf4j.MDC.getCopyOfContextMap(); 57 58 if (map != null) { 59 return new Hashtable(map); 60 } else { 61 return new Hashtable(); 62 } 63 } 64 } 65