logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1172182 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j2-api/src/main/java/org/apache/logging/log4j/message/ log4j2-api/src/test/java/org/apache/logging/log4j/message/ log4j2-core/ log4j2-core/src/test/java/org/apache/lo...
Date Sun, 18 Sep 2011 03:19:45 GMT
Author: rgoers
Date: Sun Sep 18 03:19:44 2011
New Revision: 1172182

URL: http://svn.apache.org/viewvc?rev=1172182&view=rev
Log:
Fix for Log4j2-49

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-subst.xml
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java?rev=1172182&r1=1172181&r2=1172182&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
Sun Sep 18 03:19:44 2011
@@ -95,6 +95,14 @@ public class ParameterizedMessage implem
         this.throwable = throwable;
     }
 
+    public ParameterizedMessage(String messagePattern, Object[] arguments, Throwable throwable)
{
+        this.messagePattern = messagePattern;
+        this.throwable = throwable;
+        if (arguments != null) {
+            parseArguments(arguments);
+        }
+    }
+
     /**
      * <p>This method returns a ParameterizedMessage which contains the arguments converted
to String
      * as well as an optional Throwable.</p>
@@ -138,7 +146,7 @@ public class ParameterizedMessage implem
         int argsCount = countArgumentPlaceholders(messagePattern);
         int resultArgCount = arguments.length;
         if (argsCount < arguments.length) {
-            if (arguments[arguments.length - 1] instanceof Throwable) {
+            if (throwable == null && arguments[arguments.length - 1] instanceof Throwable)
{
                 throwable = (Throwable) arguments[arguments.length - 1];
                 resultArgCount--;
             }

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java?rev=1172182&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
(added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/ParameterizedMessageTest.java
Sun Sep 18 03:19:44 2011
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.message;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class ParameterizedMessageTest {
+
+    @Test
+    public void testNoArgs() {
+        String testMsg = "Test message {}";
+        ParameterizedMessage msg = new ParameterizedMessage(testMsg, null);
+        String result = msg.getFormattedMessage();
+        assertEquals(testMsg, result);
+        Object[] array = null;
+        msg = new ParameterizedMessage(testMsg, array, null);
+        result = msg.getFormattedMessage();
+        assertEquals(testMsg, result);
+    }
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml?rev=1172182&r1=1172181&r2=1172182&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml Sun Sep 18 03:19:44
2011
@@ -60,6 +60,11 @@
       <scope>test</scope>
     </dependency>
      <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-ext</artifactId>
+      <scope>test</scope>
+    </dependency>
+     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.7</version>

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java?rev=1172182&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java
(added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java
Sun Sep 18 03:19:44 2011
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j;
+
+import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ *
+ */
+public class LogbackSubstitution {
+
+    private static final String LOGBACK_CONF = "logback.configurationFile";
+    private static final String LOGBACK_CONFIG = "logback-subst.xml";
+    private XLogger xLogger = XLoggerFactory.getXLogger(LogbackSubstitution.class);
+
+
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(LOGBACK_CONF, LOGBACK_CONFIG);
+    }
+
+    @AfterClass
+    public static void cleanupClass() {
+        System.clearProperty(LOGBACK_CONF);
+    }
+
+    @Test
+    public void testSubst() {
+        xLogger.debug("Hello, {}", "Log4j {}");
+        xLogger.debug("Hello, {}");
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-subst.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-subst.xml?rev=1172182&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-subst.xml
(added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-subst.xml
Sun Sep 18 03:19:44 2011
@@ -0,0 +1,11 @@
+<configuration>
+ <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
+   <encoder>
+     <Pattern>%d{ISO8601} %5p [%t] %c{0} - %m%n</Pattern>
+   </encoder>
+ </appender>
+
+ <root level="debug">
+   <appender-ref ref="stdout" />
+ </root>
+</configuration>
\ No newline at end of file

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java?rev=1172182&r1=1172181&r2=1172182&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-jcl/src/test/java/org/apache/logging/log4j/jcl/LoggerTest.java
Sun Sep 18 03:19:44 2011
@@ -68,6 +68,8 @@ public class LoggerTest {
         verify("List", "o.a.l.l.j.LoggerTest Exception:  MDC{}\n");
         logger.info("Info Message");
         verify("List", "o.a.l.l.j.LoggerTest Info Message MDC{}\n");
+        logger.info("Info Message {}");
+        verify("List", "o.a.l.l.j.LoggerTest Info Message {} MDC{}\n");
     }
 
     private void verify(String name, String expected) {

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java?rev=1172182&r1=1172181&r2=1172182&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/SLF4JLogger.java
Sun Sep 18 03:19:44 2011
@@ -17,6 +17,8 @@
 package org.slf4j.impl;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
@@ -33,292 +35,392 @@ import java.util.Map;
 /**
  *
  */
-public class SLF4JLogger extends AbstractLoggerWrapper implements LocationAwareLogger {
+public class SLF4JLogger implements LocationAwareLogger {
 
     private static final String FQCN = SLF4JLogger.class.getName();
     private static final Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
     private final boolean eventLogger;
+    private final AbstractLoggerWrapper logger;
+    private final String name;
 
     public SLF4JLogger(AbstractLogger logger, String name) {
-        super(logger, name);
+        Logger l = LogManager.getLogger(name);
+        this.logger = new AbstractLoggerWrapper(logger, name);
         eventLogger = "EventLogger".equals(name);
+        this.name = name;
     }
 
-    @Override
     public void trace(String format) {
-        if (isTraceEnabled()) {
-            log(null, FQCN, Level.TRACE, new SimpleMessage(format), null);
+        if (logger.isTraceEnabled()) {
+            logger.log(null, FQCN, Level.TRACE, new SimpleMessage(format), null);
         }
     }
 
     public void trace(String format, Object o) {
-        if (isTraceEnabled()) {
-            log(null, FQCN, Level.TRACE, new ParameterizedMessage(format, o), null);
+        if (logger.isTraceEnabled()) {
+            logger.log(null, FQCN, Level.TRACE, new ParameterizedMessage(format, o), null);
         }
     }
 
     public void trace(String format, Object arg1, Object arg2) {
-        if (isTraceEnabled()) {
-            log(null, FQCN, Level.TRACE, new ParameterizedMessage(format, arg1, arg2), null);
+        if (logger.isTraceEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, arg1, arg2);
+            logger.log(null, FQCN, Level.TRACE, msg, msg.getThrowable());
         }
     }
 
+    public void trace(String format, Object[] args) {
+        if (logger.isTraceEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, args);
+            logger.log(null, FQCN, Level.TRACE, msg, msg.getThrowable());
+        }
+    }
+
+    public void trace(String format, Throwable t) {
+        if (logger.isTraceEnabled()) {
+            logger.log(null, FQCN, Level.TRACE, new SimpleMessage(format), t);
+        }
+    }
+
+    public boolean isTraceEnabled() {
+        return logger.isTraceEnabled();
+    }
+
     public boolean isTraceEnabled(Marker marker) {
         return logger.isTraceEnabled((org.apache.logging.log4j.Marker) marker);
     }
 
     public void trace(Marker marker, String s) {
         if (isTraceEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE, new SimpleMessage(s),
null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE, new SimpleMessage(s),
null);
         }
     }
 
     public void trace(Marker marker, String s, Object o) {
         if (isTraceEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE, new ParameterizedMessage(s,
o), null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE,
+                new ParameterizedMessage(s, o), null);
         }
     }
 
     public void trace(Marker marker, String s, Object o, Object o1) {
         if (isTraceEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE, new ParameterizedMessage(s,
o, o1), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, o, o1);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE, msg,
msg.getThrowable());
         }
     }
 
     public void trace(Marker marker, String s, Object[] objects) {
         if (isTraceEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE,
-                new ParameterizedMessage(s, objects), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, objects);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE, msg,
msg.getThrowable());
         }
     }
 
     public void trace(Marker marker, String s, Throwable throwable) {
         if (isTraceEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE,
-                new ParameterizedMessage(s, null, throwable), throwable);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.TRACE,
+                new SimpleMessage(s), throwable);
         }
     }
 
-    @Override
     public void debug(String format) {
-        if (isDebugEnabled()) {
-            log(null, FQCN, Level.DEBUG, new SimpleMessage(format), null);
+        if (logger.isDebugEnabled()) {
+            logger.log(null, FQCN, Level.DEBUG, new SimpleMessage(format), null);
         }
     }
 
     public void debug(String format, Object o) {
-        if (isDebugEnabled()) {
-            log(null, FQCN, Level.DEBUG, new ParameterizedMessage(format, o), null);
+        if (logger.isDebugEnabled()) {
+            logger.log(null, FQCN, Level.DEBUG, new ParameterizedMessage(format, o), null);
         }
     }
 
     public void debug(String format, Object arg1, Object arg2) {
-        if (isDebugEnabled()) {
-            log(null, FQCN, Level.DEBUG, new ParameterizedMessage(format, arg1, arg2), null);
+        if (logger.isDebugEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, arg1, arg2);
+            logger.log(null, FQCN, Level.DEBUG, msg, msg.getThrowable());
+        }
+    }
+
+    public void debug(String format, Object[] args) {
+        if (logger.isDebugEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, args);
+            logger.log(null, FQCN, Level.DEBUG, msg, msg.getThrowable());
+        }
+    }
+
+    public void debug(String format, Throwable t) {
+        if (logger.isDebugEnabled()) {
+            logger.log(null, FQCN, Level.DEBUG, new SimpleMessage(format), t);
         }
     }
 
+    public boolean isDebugEnabled() {
+        return logger.isDebugEnabled();
+    }
+
     public boolean isDebugEnabled(Marker marker) {
         return logger.isDebugEnabled((org.apache.logging.log4j.Marker) marker);
     }
 
     public void debug(Marker marker, String s) {
         if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG, new SimpleMessage(s),
null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG, new SimpleMessage(s),
null);
         }
     }
 
     public void debug(Marker marker, String s, Object o) {
         if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG, new ParameterizedMessage(s,
o), null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG,
+                new ParameterizedMessage(s, o), null);
         }
     }
 
     public void debug(Marker marker, String s, Object o, Object o1) {
         if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG, new ParameterizedMessage(s,
o, o1), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, o, o1);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG, msg,
msg.getThrowable());
         }
     }
 
     public void debug(Marker marker, String s, Object[] objects) {
         if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG,
-                new ParameterizedMessage(s, objects), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, objects);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG, msg,
msg.getThrowable());
         }
     }
 
     public void debug(Marker marker, String s, Throwable throwable) {
         if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG,
-                new ParameterizedMessage(s, null, throwable), throwable);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.DEBUG,
+                new SimpleMessage(s), throwable);
         }
     }
 
-    @Override
     public void info(String format) {
-        if (isInfoEnabled()) {
-            log(null, FQCN, Level.INFO, new SimpleMessage(format), null);
+        if (logger.isInfoEnabled()) {
+            logger.log(null, FQCN, Level.INFO, new SimpleMessage(format), null);
         }
     }
 
     public void info(String format, Object o) {
-        if (isInfoEnabled()) {
-            log(null, FQCN, Level.INFO, new ParameterizedMessage(format, o), null);
+        if (logger.isInfoEnabled()) {
+            logger.log(null, FQCN, Level.INFO, new ParameterizedMessage(format, o), null);
         }
     }
 
     public void info(String format, Object arg1, Object arg2) {
-        if (isInfoEnabled()) {
-            log(null, FQCN, Level.INFO, new ParameterizedMessage(format, arg1, arg2), null);
+        if (logger.isInfoEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, arg1, arg2);
+            logger.log(null, FQCN, Level.INFO, msg, msg.getThrowable());
         }
     }
 
+    public void info(String format, Object[] args) {
+        if (logger.isInfoEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, args);
+            logger.log(null, FQCN, Level.INFO, msg, msg.getThrowable());
+        }
+    }
+
+    public void info(String format, Throwable t) {
+        if (logger.isInfoEnabled()) {
+            logger.log(null, FQCN, Level.INFO, new SimpleMessage(format), t);
+        }
+    }
+
+    public boolean isInfoEnabled() {
+        return logger.isInfoEnabled();
+    }
+
     public boolean isInfoEnabled(Marker marker) {
         return logger.isInfoEnabled((org.apache.logging.log4j.Marker) marker);
     }
 
     public void info(Marker marker, String s) {
         if (isInfoEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO, new SimpleMessage(s),
null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO, new SimpleMessage(s),
null);
         }
     }
 
     public void info(Marker marker, String s, Object o) {
         if (isInfoEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO, new ParameterizedMessage(s,
o), null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO,
+                new ParameterizedMessage(s, o), null);
         }
     }
 
     public void info(Marker marker, String s, Object o, Object o1) {
         if (isInfoEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO, new ParameterizedMessage(s,
o, o1), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, o, o1);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO, msg, msg.getThrowable());
         }
     }
 
     public void info(Marker marker, String s, Object[] objects) {
         if (isInfoEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO,
-                new ParameterizedMessage(s, objects), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, objects);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO, msg, msg.getThrowable());
         }
     }
 
     public void info(Marker marker, String s, Throwable throwable) {
         if (isInfoEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO,
-                new ParameterizedMessage(s, null, throwable), throwable);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.INFO,
+                new SimpleMessage(s), throwable);
         }
     }
 
-    @Override
     public void warn(String format) {
-        if (isWarnEnabled()) {
-            log(null, FQCN, Level.WARN, new SimpleMessage(format), null);
+        if (logger.isWarnEnabled()) {
+            logger.log(null, FQCN, Level.WARN, new SimpleMessage(format), null);
         }
     }
 
     public void warn(String format, Object o) {
-        if (isWarnEnabled()) {
-            log(null, FQCN, Level.WARN, new ParameterizedMessage(format, o), null);
+        if (logger.isWarnEnabled()) {
+            logger.log(null, FQCN, Level.WARN, new ParameterizedMessage(format, o), null);
         }
     }
 
     public void warn(String format, Object arg1, Object arg2) {
-        if (isWarnEnabled()) {
-            log(null, FQCN, Level.WARN, new ParameterizedMessage(format, arg1, arg2), null);
+        if (logger.isWarnEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, arg1, arg2);
+            logger.log(null, FQCN, Level.WARN, msg, msg.getThrowable());
+        }
+    }
+
+    public void warn(String format, Object[] args) {
+        if (logger.isWarnEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, args);
+            logger.log(null, FQCN, Level.WARN, msg, msg.getThrowable());
+        }
+    }
+
+    public void warn(String format, Throwable t) {
+        if (logger.isWarnEnabled()) {
+            logger.log(null, FQCN, Level.WARN, new SimpleMessage(format), t);
         }
     }
 
+    public boolean isWarnEnabled() {
+        return logger.isWarnEnabled();
+    }
+
     public boolean isWarnEnabled(Marker marker) {
         return logger.isWarnEnabled((org.apache.logging.log4j.Marker) marker);
     }
 
     public void warn(Marker marker, String s) {
         if (isWarnEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN, new SimpleMessage(s),
null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN, new SimpleMessage(s),
null);
         }
     }
 
     public void warn(Marker marker, String s, Object o) {
-        if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN, new ParameterizedMessage(s,
o), null);
+        if (isWarnEnabled(marker)) {
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN,
+                new ParameterizedMessage(s, o), null);
         }
     }
 
     public void warn(Marker marker, String s, Object o, Object o1) {
-        if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN, new ParameterizedMessage(s,
o, o1), null);
+        if (isWarnEnabled(marker)) {
+            ParameterizedMessage msg = new ParameterizedMessage(s, o, o1);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN, msg, msg.getThrowable());
         }
     }
 
     public void warn(Marker marker, String s, Object[] objects) {
-        if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN,
-                new ParameterizedMessage(s, objects), null);
+        if (isWarnEnabled(marker)) {
+            ParameterizedMessage msg = new ParameterizedMessage(s, objects);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN, msg, msg.getThrowable());
         }
     }
 
     public void warn(Marker marker, String s, Throwable throwable) {
-        if (isDebugEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN,
-                new ParameterizedMessage(s, null, throwable), throwable);
+        if (isWarnEnabled(marker)) {
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.WARN,
+                new SimpleMessage(s), throwable);
         }
     }
 
-    @Override
     public void error(String format) {
-        if (isErrorEnabled()) {
-            log(null, FQCN, Level.ERROR, new SimpleMessage(format), null);
+        if (logger.isErrorEnabled()) {
+            logger.log(null, FQCN, Level.ERROR, new SimpleMessage(format), null);
         }
     }
 
     public void error(String format, Object o) {
-        if (isErrorEnabled()) {
-            log(null, FQCN, Level.ERROR, new ParameterizedMessage(format, o), null);
+        if (logger.isErrorEnabled()) {
+            logger.log(null, FQCN, Level.ERROR, new ParameterizedMessage(format, o), null);
         }
     }
 
     public void error(String format, Object arg1, Object arg2) {
-        if (isErrorEnabled()) {
-            log(null, FQCN, Level.ERROR, new ParameterizedMessage(format, arg1, arg2), null);
+        if (logger.isErrorEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, arg1, arg2);
+            logger.log(null, FQCN, Level.ERROR, msg, msg.getThrowable());
+        }
+    }
+
+    public void error(String format, Object[] args) {
+        if (logger.isErrorEnabled()) {
+            ParameterizedMessage msg = new ParameterizedMessage(format, args);
+            logger.log(null, FQCN, Level.ERROR, msg, msg.getThrowable());
+        }
+    }
+
+    public void error(String format, Throwable t) {
+        if (logger.isErrorEnabled()) {
+            logger.log(null, FQCN, Level.ERROR, new SimpleMessage(format), t);
         }
     }
 
+    public boolean isErrorEnabled() {
+        return logger.isErrorEnabled();
+    }
+
     public boolean isErrorEnabled(Marker marker) {
         return logger.isErrorEnabled((org.apache.logging.log4j.Marker) marker);
     }
 
     public void error(Marker marker, String s) {
         if (isErrorEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR, new SimpleMessage(s),
null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR, new SimpleMessage(s),
null);
         }
     }
 
     public void error(Marker marker, String s, Object o) {
         if (isErrorEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR, new ParameterizedMessage(s,
o), null);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR,
+                new ParameterizedMessage(s, o), null);
         }
     }
 
     public void error(Marker marker, String s, Object o, Object o1) {
         if (isErrorEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR, new ParameterizedMessage(s,
o, o1), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, o, o1);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR, msg,
msg.getThrowable());
         }
     }
 
     public void error(Marker marker, String s, Object[] objects) {
         if (isErrorEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR,
-                new ParameterizedMessage(s, objects), null);
+            ParameterizedMessage msg = new ParameterizedMessage(s, objects);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR, msg,
msg.getThrowable());
         }
     }
 
     public void error(Marker marker, String s, Throwable throwable) {
         if (isErrorEnabled(marker)) {
-            log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR,
-                new ParameterizedMessage(s, null, throwable), throwable);
+            logger.log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR,
+                new SimpleMessage(s), throwable);
         }
     }
 
+
     public void log(Marker marker, String fqcn, int i, String s1, Object[] objects, Throwable
throwable) {
         Message msg;
         if (eventLogger && marker != null && marker.contains(EVENT_MARKER))
{
@@ -338,21 +440,21 @@ public class SLF4JLogger extends Abstrac
                 msg = new ParameterizedMessage(s1, objects, throwable);
             }
 
+       } else if (objects == null) {
+            msg = new SimpleMessage(s1);
         } else {
             msg = new ParameterizedMessage(s1, objects, throwable);
+            if (throwable != null) {
+                throwable = ((ParameterizedMessage) msg).getThrowable();
+            }
         }
-        log((org.apache.logging.log4j.Marker) marker, fqcn, getLevel(i), msg, throwable);
+        logger.log((org.apache.logging.log4j.Marker) marker, fqcn, getLevel(i), msg, throwable);
     }
 
     public String getName() {
         return name;
     }
 
-    @Override
-    protected String getFQCN() {
-        return FQCN;
-    }
-
     private Level getLevel(int i) {
 
         switch (i) {

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java?rev=1172182&r1=1172181&r2=1172182&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
Sun Sep 18 03:19:44 2011
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.junit.AfterClass;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -33,6 +34,8 @@ import org.slf4j.ext.EventData;
 import org.slf4j.ext.EventLogger;
 import org.slf4j.ext.XLogger;
 import org.slf4j.ext.XLoggerFactory;
+import org.slf4j.impl.SLF4JLogger;
+import org.slf4j.spi.LocationAwareLogger;
 
 import java.util.List;
 import java.util.Locale;
@@ -106,6 +109,17 @@ public class LoggerTest {
         verify("List", "o.a.l.s.LoggerTest Debug message MDC{}\n");
     }
 
+    @Test
+    public void debugNoParms() {
+        logger.debug("Debug message {}");
+        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}\n");
+        logger.debug("Debug message {}", (Object[]) null);
+        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}\n");
+        ((LocationAwareLogger)logger).log(null, SLF4JLogger.class.getName(), LocationAwareLogger.DEBUG_INT,
+            "Debug message {}", null, null);
+        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}\n");
+    }
+
 
     @Test
     public void debugWithParms() {
@@ -125,6 +139,14 @@ public class LoggerTest {
     }
 
     @Test
+    public void doubleSubst() {
+        logger.debug("Hello, {}", "Log4j {}");
+        verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}\n");
+        //xlogger.debug("Hello, {}", "Log4j {}");
+        //verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}\n");
+    }
+
+    @Test
     public void testEventLogger() {
         MDC.put("loginId", "JohnDoe");
         MDC.put("ipAddress", "192.168.0.120");
@@ -153,4 +175,14 @@ public class LoggerTest {
         assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected,
actual);
         ((ListAppender) listApp).clear();
     }
+
+    @Before
+    public void cleanup()
+    {
+        Map<String, Appender> list = ctx.getConfiguration().getAppenders();
+        Appender listApp = list.get("List");
+        ((ListAppender) listApp).clear();
+        Appender eventApp = list.get("EventLogger");
+        ((ListAppender) eventApp).clear();
+    }
 }



Mime
View raw message