[LOGBack-dev] svn commit: r555 - logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net

noreply.seb at qos.ch noreply.seb at qos.ch
Mon Sep 11 16:47:57 CEST 2006


Author: seb
Date: Mon Sep 11 16:47:57 2006
New Revision: 555

Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppenderTestApp.java

Log:
added MDC

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppenderTestApp.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppenderTestApp.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SMTPAppenderTestApp.java	Mon Sep 11 16:47:57 2006
@@ -4,45 +4,48 @@
 
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.MDC;
 import ch.qos.logback.classic.PatternLayout;
 import ch.qos.logback.core.Layout;
 import ch.qos.logback.core.util.StatusPrinter;
 
 public class SMTPAppenderTestApp {
 
-	public static void main(String[] args) {
+  public static void main(String[] args) {
+
+    Logger logger = (Logger) LoggerFactory
+        .getLogger(SocketAppenderTestApp.class);
+    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+    MDC.put("key", "testValue");
+    SMTPAppender appender = new SMTPAppender();
+    appender.setContext(lc);
+    appender.setName("smtp");
+    appender.setFrom("user at host.dom");
+    appender.setLayout(buildLayout(lc));
+    appender.setSMTPHost("mail.qos.ch");
+    appender.setSubject("logging report");
+    appender.setTo("sebastien.nospam at qos.ch");
+
+    appender.start();
+
+    logger.addAppender(appender);
+
+    for (int i = 0; i <= 10; i++) {
+      logger.debug("** Hello world. n=" + i);
+    }
+    logger.error("Triggering request");
+
+    StatusPrinter.print(lc.getStatusManager());
+  }
+
+  private static Layout buildLayout(LoggerContext lc) {
+    PatternLayout layout = new PatternLayout();
+    layout.setContext(lc);
+    layout.setHeader("Some header\n");
+    layout.setPattern("%-4relative [%thread] %-5level %class - %msg %X{test}%n");
+    layout.setFooter("Some footer");
+    layout.start();
+    return layout;
+  }
 
-		Logger logger = (Logger) LoggerFactory.getLogger(SocketAppenderTestApp.class);
-		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-		SMTPAppender appender = new SMTPAppender();
-		appender.setContext(lc);
-		appender.setName("smtp");
-		appender.setFrom("user at host.dom");
-		appender.setLayout(buildLayout(lc));
-		appender.setSMTPHost("mail.qos.ch");
-		appender.setSubject("logging report");
-		appender.setTo("sebastien.nospam at qos.ch");
-		
-		appender.start();
-
-		logger.addAppender(appender);
-
-		for (int i = 0; i <= 10; i++) {
-			logger.debug("** Hello world. n=" + i);
-		}
-		logger.error("Triggering request");
-		
-		StatusPrinter.print(lc.getStatusManager());
-	}
-	
-	private static Layout buildLayout(LoggerContext lc) {
-		PatternLayout layout = new PatternLayout();
-		layout.setContext(lc);
-		layout.setHeader("Some header\n");
-		layout.setPattern("%-4relative [%thread] %-5level %class - %msg%n");
-		layout.setFooter("Some footer");
-		layout.start();
-		return layout;
-	}
-	
 }



More information about the logback-dev mailing list