[LOGBack-dev] svn commit: r549 - in logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic: . pattern

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Sep 8 18:39:55 CEST 2006


Author: seb
Date: Fri Sep  8 18:39:55 2006
New Revision: 549

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MDCConverter.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java

Log:
- initial commit of MDCConverter.java
- updated PatternLayout accordingly

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java	Fri Sep  8 18:39:55 2006
@@ -20,6 +20,7 @@
 import ch.qos.logback.classic.pattern.LineOfCallerConverter;
 import ch.qos.logback.classic.pattern.LineSeparatorConverter;
 import ch.qos.logback.classic.pattern.LoggerConverter;
+import ch.qos.logback.classic.pattern.MDCConverter;
 import ch.qos.logback.classic.pattern.MessageConverter;
 import ch.qos.logback.classic.pattern.MethodOfCallerConverter;
 import ch.qos.logback.classic.pattern.NopThrowableInformationConverter;
@@ -73,6 +74,8 @@
 
     defaultConverterMap.put("F", FileOfCallerConverter.class.getName());
     defaultConverterMap.put("file", FileOfCallerConverter.class.getName());
+    
+    defaultConverterMap.put("X", MDCConverter.class.getName());
 
     defaultConverterMap
         .put("ex", ThrowableInformationConverter.class.getName());

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MDCConverter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/MDCConverter.java	Fri Sep  8 18:39:55 2006
@@ -0,0 +1,24 @@
+package ch.qos.logback.classic.pattern;
+
+import java.util.Map;
+
+import ch.qos.logback.classic.spi.LoggingEvent;
+
+public class MDCConverter extends ClassicConverter {
+	
+	public MDCConverter() {
+	}
+
+	@Override
+	public String convert(Object event) {
+		LoggingEvent loggingEvent = (LoggingEvent)event;
+		Map<String, String> mdcPropertyMap = loggingEvent.getMDCPropertyMap();
+		if(mdcPropertyMap != null) {
+			return loggingEvent.getMDCPropertyMap().get(getFirstOption());
+		} else {
+			return "";
+		}
+	}
+}
+
+



More information about the logback-dev mailing list