logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1419187 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Date Mon, 10 Dec 2012 01:31:40 GMT
Author: ggregory
Date: Mon Dec 10 01:31:39 2012
New Revision: 1419187

URL: http://svn.apache.org/viewvc?rev=1419187&view=rev
Log:
[LOG4J2-133] Allow custom message creation via a message factory. Part 2: LogManager changes.
Add core tests. Fix warning message.

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java?rev=1419187&r1=1419186&r2=1419187&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
Mon Dec 10 01:31:39 2012
@@ -99,7 +99,7 @@ public abstract class AbstractLogger imp
             StatusLogger
                     .getLogger()
                     .warn("The Logger {} was created with the message factory {} and is now
requested with a null message factory (defaults to {}), which may create log events with unexpected
formatting.",
-                            name, loggerMessageFactory, messageFactory);
+                            name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName());
         }
     }
 

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java?rev=1419187&r1=1419186&r2=1419187&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Mon Dec 10 01:31:39 2012
@@ -16,28 +16,32 @@
  */
 package org.apache.logging.log4j.core;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
-import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.message.ParameterizedMessageFactory;
+import org.apache.logging.log4j.message.StringFormatterMessageFactory;
 import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.io.File;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-
 /**
  *
  */
@@ -124,6 +128,33 @@ public class LoggerTest {
     }
 
     @Test
+    public void getLogger_String_MessageFactoryMismatch() {
+        Logger testLogger =  testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatch",
new StringFormatterMessageFactory(), new ParameterizedMessageFactory());
+        testLogger.debug("%,d", Integer.MAX_VALUE);
+        List<LogEvent> events = app.getEvents();
+        assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size()
== 1);        
+        assertEquals(String.format("%,d", Integer.MAX_VALUE), events.get(0).getMessage().getFormattedMessage());
+    }
+
+    @Test
+    public void getLogger_String_MessageFactoryMismatchNull() {
+        Logger testLogger =  testMessageFactoryMismatch("getLogger_String_MessageFactoryMismatchNull",
new StringFormatterMessageFactory(), null);
+        testLogger.debug("%,d", Integer.MAX_VALUE);
+        List<LogEvent> events = app.getEvents();
+        assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size()
== 1);        
+        assertEquals(String.format("%,d", Integer.MAX_VALUE), events.get(0).getMessage().getFormattedMessage());
+    }
+
+    private Logger testMessageFactoryMismatch(String name, MessageFactory messageFactory1,
MessageFactory messageFactory2) {
+        Logger testLogger = (Logger) LogManager.getLogger(name, messageFactory1);
+        assertNotNull(testLogger);
+        assertEquals(messageFactory1, testLogger.getMessageFactory());
+        Logger testLogger2 = (Logger) LogManager.getLogger(name, messageFactory2);
+        assertEquals(messageFactory1, testLogger2.getMessageFactory());
+        return testLogger;
+    }
+
+    @Test
     public void debugObject() {
         logger.debug(new Date());
         List<LogEvent> events = app.getEvents();



Mime
View raw message