logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1172203 - /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
Date Sun, 18 Sep 2011 06:17:43 GMT
Author: rgoers
Date: Sun Sep 18 06:17:43 2011
New Revision: 1172203

URL: http://svn.apache.org/viewvc?rev=1172203&view=rev
Log:
Test that class name in log message is correct

Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java?rev=1172203&r1=1172202&r2=1172203&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
Sun Sep 18 06:17:43 2011
@@ -17,9 +17,11 @@
 
 package org.apache.log4j;
 
+import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.ListAppender;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -34,6 +36,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Method;
+import java.util.List;
 
 
 /**
@@ -118,6 +121,23 @@ public class CategoryTest {
         logger.setPriority(debug);
     }
 
+    @Test
+    public void testClassName() {
+        Category category = Category.getInstance("TestCategory");
+        Layout layout = PatternLayout.createLayout("%d %p %C{1.} [%t] %m%n", null);
+        ListAppender appender = new ListAppender("List2", null, layout, false, false);
+        appender.start();
+        category.setAdditivity(false);
+        category.getLogger().addAppender(appender);
+        category.error("Test Message");
+        List<String> msgs = appender.getMessages();
+        assertTrue("Incorrect number of messages. Expected 1 got " + msgs.size(), msgs.size()
== 1);
+        String msg = msgs.get(0);
+        appender.clear();
+        String expected = "ERROR o.a.l.CategoryTest [main] Test Message\n";
+        assertTrue("Incorrect message.", msg.endsWith(expected));
+    }
+
     /**
      * Derived category to check method signature of forcedLog.
      */



Mime
View raw message