logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1395865 - in /logging/log4j/log4j2/trunk: log4j12-api/src/main/java/org/apache/log4j/Category.java log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java src/changes/changes.xml
Date Tue, 09 Oct 2012 06:24:56 GMT
Author: rgoers
Date: Tue Oct  9 06:24:56 2012
New Revision: 1395865

URL: http://svn.apache.org/viewvc?rev=1395865&view=rev
Log:
Log4j 1.2 Category.forcedLog was wrapping the message with an ObjectMessage even if the parameter
was an ObjectMessage

Modified:
    logging/log4j/log4j2/trunk/log4j12-api/src/main/java/org/apache/log4j/Category.java
    logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j12-api/src/main/java/org/apache/log4j/Category.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j12-api/src/main/java/org/apache/log4j/Category.java?rev=1395865&r1=1395864&r2=1395865&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j12-api/src/main/java/org/apache/log4j/Category.java (original)
+++ logging/log4j/log4j2/trunk/log4j12-api/src/main/java/org/apache/log4j/Category.java Tue
Oct  9 06:24:56 2012
@@ -250,7 +250,8 @@ public class Category {
 
     public void forcedLog(String fqcn, Priority level, Object message, Throwable t) {
         org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
-        logger.log(null, fqcn, lvl, new ObjectMessage(message), t);
+        Message msg = message instanceof Message ? (ObjectMessage) message : new ObjectMessage(message);
+        logger.log(null, fqcn, lvl, msg, t);
     }
 
     public boolean exists(String name) {

Modified: logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java?rev=1395865&r1=1395864&r2=1395865&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/CategoryTest.java
Tue Oct  9 06:24:56 2012
@@ -18,9 +18,10 @@
 package org.apache.log4j;
 
 import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.status.StatusConsoleListener;
-import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.ObjectMessage;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.layout.PatternLayout;
@@ -70,8 +71,25 @@ public class CategoryTest {
         category.setAdditivity(false);
         category.getLogger().addAppender(appender);
         category.info("Hello, World");
-        int events = appender.getEvents().size();
+        List<LogEvent> list = appender.getEvents();
+        int events = list.size();
         assertTrue("Number of events should be 1, was " + events, events == 1);
+        LogEvent event = list.get(0);
+        Message msg = event.getMessage();
+        assertNotNull("No message", msg);
+        assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
+        Object[] objects = msg.getParameters();
+        assertTrue("Incorrect Object type", objects[0] instanceof String);
+        appender.clear();
+        category.log(Priority.INFO, "Hello, World");
+        events = list.size();
+        assertTrue("Number of events should be 1, was " + events, events == 1);
+        event = list.get(0);
+        msg = event.getMessage();
+        assertNotNull("No message", msg);
+        assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
+        objects = msg.getParameters();
+        assertTrue("Incorrect Object type", objects[0] instanceof String);
         appender.clear();
     }
 

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1395865&r1=1395864&r2=1395865&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Oct  9 06:24:56 2012
@@ -22,6 +22,12 @@
   </properties>
 
   <body>
+    <release version="2.0-beta3" date="TBD" description= "Bug fixes and enhancements">
+      <action dev="rgoers" type="fix">
+        Log4j 1.2 Category.forcedLog was wrapping the message with an ObjectMessage even
if the parameter was an
+        ObjectMessage.
+      </action>
+    </release>
     <release version="2.0-beta2" date="2012-10-07" description="Bug fixes and enhancements">
       <action dev="rgoers" type="update">
         Made ParameterizedMessage, StringFormattedMessage and ThreadDumpMessage immutable.
LocalizedMessage is



Mime
View raw message