logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1501658 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/main/java/org/apache/logging/log4j/spi/ api/src/test/java/org/apache/logging/log4j/ src/changes/
Date Wed, 10 Jul 2013 06:30:33 GMT
Author: rgoers
Date: Wed Jul 10 06:30:33 2013
New Revision: 1501658

URL: http://svn.apache.org/r1501658
Log:
LOG4J2-301 - Add printf methods to Logger API

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

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java?rev=1501658&r1=1501657&r2=1501658&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java Wed
Jul 10 06:30:33 2013
@@ -841,6 +841,23 @@ public interface Logger {
   void log(Level level, String message, Throwable t);
 
   /**
+   * Logs a formatted message using the specified format string and arguments.
+   * @param level The logging Level.
+   * @param format The format String.
+   * @param params Arguments specified by the format.
+   */
+  void printf(Level level, String format, Object... params);
+
+  /**
+   * Logs a formatted message using the specified format string and arguments.
+   * @param level The logging Level.
+   * @param marker the marker data specific to this log statement.
+   * @param format The format String.
+   * @param params Arguments specified by the format.
+   */
+  void printf(Level level, Marker marker, String format, Object... params);
+
+  /**
    * Logs an exception or error to be thrown. This may be coded as <br />
    *    throw logger.throwing(debug, myException);
    * @param <T> the Throwable type.

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=1501658&r1=1501657&r2=1501658&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
Wed Jul 10 06:30:33 2013
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.MarkerMa
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.ParameterizedMessageFactory;
+import org.apache.logging.log4j.message.StringFormattedMessage;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -1449,6 +1450,33 @@ public abstract class AbstractLogger imp
     }
 
     /**
+     * Logs a formatted message using the specified format string and arguments.
+     * @param level The logging Level.
+     * @param format The format String.
+     * @param params Arguments specified by the format.
+     */
+    public void printf(Level level, String format, Object... params) {
+        if (isEnabled(level, null, format, params)) {
+            Message msg = new StringFormattedMessage(format, params);
+            log(null, FQCN, level, msg, msg.getThrowable());
+        }
+    }
+
+    /**
+     * Logs a formatted message using the specified format string and arguments.
+     * @param level The logging Level.
+     * @param marker the marker data specific to this log statement.
+     * @param format The format String.
+     * @param params Arguments specified by the format.
+     */
+    public void printf(Level level, Marker marker, String format, Object... params) {
+        if (isEnabled(level, null, format, params)) {
+            Message msg = new StringFormattedMessage(format, params);
+            log(marker, FQCN, level, msg, msg.getThrowable());
+        }
+    }
+
+    /**
      * Logs a message with location information.
      *
      * @param marker The Marker

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1501658&r1=1501657&r2=1501658&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Wed Jul 10 06:30:33 2013
@@ -238,6 +238,15 @@ public class LoggerTest {
         assertEquals(String.format(" DEBUG %,d", Integer.MAX_VALUE), testLogger.getEntries().get(0));
     }
 
+    @Test
+    public void printf() {
+        logger.printf(Level.DEBUG, "Debug message %d", 1);
+        logger.printf(Level.DEBUG, MarkerManager.getMarker("Test"), "Debug message %d", 2);
+        assertEquals(2, results.size());
+        assertTrue("Incorrect message", results.get(0).startsWith(" DEBUG Debug message 1"));
+        assertTrue("Incorrect message", results.get(1).startsWith(" DEBUG Debug message 2"));
+    }
+
     public void getLoggerByNullClass() {
         // Returns a SimpleLogger
         Assert.assertNotNull(LogManager.getLogger((Class<?>) null));

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1501658&r1=1501657&r2=1501658&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Jul 10 06:30:33 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta8" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-301" dev="rgoers" type="update">
+        Add printf methods to Logger API.
+      </action>
       <action issue="LOG4J2-300" dev="rgoers" type="fix">
         WriterThread was ending when no agents are available which caused an OutOfMemoryError.
       </action>



Mime
View raw message