logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1389725 - in /logging/log4j/log4j2/trunk: log4j12-api/src/main/java/org/apache/log4j/Category.java log4j12-api/src/test/java/org/apache/log4j/LoggerTest.java src/changes/changes.xml
Date Tue, 25 Sep 2012 06:28:58 GMT
Author: rgoers
Date: Tue Sep 25 06:28:58 2012
New Revision: 1389725

URL: http://svn.apache.org/viewvc?rev=1389725&view=rev
Log:
LOG4J2-91 Log4j 1.2 adapter's Category class was missing 3 log methods

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/LoggerTest.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=1389725&r1=1389724&r2=1389725&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
Sep 25 06:28:58 2012
@@ -21,6 +21,8 @@ import org.apache.logging.log4j.core.hel
 import org.apache.logging.log4j.message.LocalizedMessage;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ObjectMessage;
+import org.apache.logging.log4j.message.ParameterizedMessage;
+import org.apache.logging.log4j.message.SimpleMessage;
 
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -301,6 +303,27 @@ public class Category {
         }
     }
 
+    public void log(Priority priority, Object message, Throwable t) {
+        if (isEnabledFor(priority)) {
+            Message msg = new ObjectMessage(message);
+            forcedLog(FQCN, priority, msg, t);
+        }
+    }
+
+    public void log(Priority priority, Object message) {
+        if (isEnabledFor(priority)) {
+            Message msg = new ObjectMessage(message);
+            forcedLog(FQCN, priority, msg, null);
+        }
+    }
+
+    public void log(String fqcn, Priority priority, Object message, Throwable t) {
+        if (isEnabledFor(priority)) {
+            Message msg = new ObjectMessage(message);
+            forcedLog(fqcn, priority, msg, t);
+        }
+    }
+
     private void maybeLog(String fqcn, org.apache.logging.log4j.Level level,
             Object message, Throwable throwable) {
         if (logger.isEnabled(level, null, message, throwable)) {

Modified: logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggerTest.java?rev=1389725&r1=1389724&r2=1389725&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggerTest.java
Tue Sep 25 06:28:58 2012
@@ -26,6 +26,7 @@ import java.util.ResourceBundle;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.AppenderBase;
+import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.junit.After;
@@ -434,6 +435,36 @@ public class LoggerTest {
         assertFalse(root.isTraceEnabled());
     }
 
+    @Test
+    public void testLog() {
+        PatternLayout layout = PatternLayout.createLayout("%d %C %L %m", null, null, null);
+        ListAppender appender = new ListAppender("List", null, layout, false, false);
+        Logger root = Logger.getRootLogger();
+        root.getLogger().addAppender(appender);
+        root.setLevel(Level.INFO);
+        MyLogger log = new MyLogger(root);
+        log.logInfo("This is a test", null);
+        root.log(Priority.INFO, "Test msg2", null);
+        root.log(Priority.INFO, "Test msg3");
+        List<String> msgs = appender.getMessages();
+        assertTrue("Incorrect number of messages", msgs.size() == 3);
+        String msg = msgs.get(0);
+        assertTrue("Message contains incorrect class name: " + msg, msg.contains(LoggerTest.class.getName()));
+    }
+
+    private static class MyLogger {
+
+        private Logger logger;
+
+        public MyLogger(Logger logger) {
+            this.logger = logger;
+        }
+
+        public void logInfo(String msg, Throwable t) {
+            logger.log(MyLogger.class.getName(), Priority.INFO, msg, t);
+        }
+    }
+
     private static class CountingAppender extends AppenderBase {
 
         int counter;

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1389725&r1=1389724&r2=1389725&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Sep 25 06:28:58 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta2" date="TBD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-91" dev="rgoers" type="fix">
+        Log4j 1.2 adapter's Category class was missing 3 log methods.
+      </action>
       <action issue="LOG4J2-84" dev="rgoers" type="fix">
         If the ThreadContext stack is empty the LogEvent will contain a null value to reduce
the overhead of
         creating log events and in the size of the serialized object. Changed the ThreadContext
stack to use



Mime
View raw message