[LOGBack-dev] svn commit: r475 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic test/java/ch/qos/logback/classic

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Aug 22 14:53:39 CEST 2006


Author: seb
Date: Tue Aug 22 14:53:38 2006
New Revision: 475

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/PatternLayout.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
Log:
added support for patterns "p" and "c" from log4j, respectively equals to "level" and "logger" in logback

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	Tue Aug 22 14:53:38 2006
@@ -49,13 +49,15 @@
 
     defaultConverterMap.put("level", LevelConverter.class.getName());
     defaultConverterMap.put("le", LevelConverter.class.getName());
-
+    defaultConverterMap.put("p", LevelConverter.class.getName());
+    
     defaultConverterMap.put("t", ThreadConverter.class.getName());
     defaultConverterMap.put("thread", ThreadConverter.class.getName());
 
     defaultConverterMap.put("lo", LoggerConverter.class.getName());
     defaultConverterMap.put("logger", LoggerConverter.class.getName());
-
+    defaultConverterMap.put("c", LoggerConverter.class.getName());
+    
     defaultConverterMap.put("m", MessageConverter.class.getName());
     defaultConverterMap.put("msg", MessageConverter.class.getName());
     defaultConverterMap.put("message", MessageConverter.class.getName());

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/PatternLayoutTest.java	Tue Aug 22 14:53:38 2006
@@ -88,6 +88,19 @@
     assertTrue(!val.contains("java.lang.Exception: Bogus exception"));
   }
   
+  public void testWithLettersComingFromLog4j() {
+    PatternLayout pl = new PatternLayout();
+    //Letters: p = level and c = logger
+    pl.setPattern("%d %p [%t] %c{30} - %m%n");
+    Context context = new LoggerContext();
+    pl.setContext(context);
+    pl.start();
+    String val = pl.doLayout(getEventObject());
+    // 2006-02-01 22:38:06,212 INFO [main] c.q.l.pattern.ConverterTest - Some message
+    String regex = Contants4T.ISO_REGEX+" INFO \\[main] c.q.l.c.pattern.ConverterTest - Some message\\s*";
+    assertTrue(val.matches(regex));
+  }
+  
   static public Test suite() {
     TestSuite suite = new TestSuite();
     //suite.addTest(new PatternLayoutTest("testNopExeptionHandler"));



More information about the logback-dev mailing list