logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1487890 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/message/ api/src/test/java/org/apache/logging/log4j/message/ src/changes/
Date Thu, 30 May 2013 15:14:55 GMT
Author: rgoers
Date: Thu May 30 15:14:54 2013
New Revision: 1487890

URL: http://svn.apache.org/r1487890
Log:
LOG4J2-242 - StringFormattedMessage and MessageFormatMessage now will accept a Throwable as
their last argument and pass it on

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MessageFormatMessage.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatMessageTest.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StringFormattedMessageTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MessageFormatMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MessageFormatMessage.java?rev=1487890&r1=1487889&r2=1487890&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MessageFormatMessage.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/MessageFormatMessage.java
Thu May 30 15:14:54 2013
@@ -41,10 +41,14 @@ public class MessageFormatMessage implem
     private transient Object[] argArray;
     private String[] stringArgs;
     private transient String formattedMessage;
+    private transient Throwable throwable;
 
     public MessageFormatMessage(final String messagePattern, final Object... arguments) {
         this.messagePattern = messagePattern;
         this.argArray = arguments;
+        if (arguments != null && arguments.length > 0 && arguments[arguments.length
- 1] instanceof Throwable) {
+            this.throwable = (Throwable) arguments[arguments.length - 1];
+        }
     }
 
     /**
@@ -150,12 +154,12 @@ public class MessageFormatMessage implem
     }
 
     /**
-     * Always returns null.
+     * Return the throwable passed to the Message.
      *
-     * @return null
+     * @return the Throwable.
      */
     @Override
     public Throwable getThrowable() {
-        return null;
+        return throwable;
     }
 }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java?rev=1487890&r1=1487889&r2=1487890&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StringFormattedMessage.java
Thu May 30 15:14:54 2013
@@ -40,10 +40,14 @@ public class StringFormattedMessage impl
     private transient Object[] argArray;
     private String[] stringArgs;
     private transient String formattedMessage;
+    private transient Throwable throwable;
 
     public StringFormattedMessage(final String messagePattern, final Object... arguments)
{
         this.messagePattern = messagePattern;
         this.argArray = arguments;
+        if (arguments != null && arguments.length > 0 && arguments[arguments.length
- 1] instanceof Throwable) {
+            this.throwable = (Throwable) arguments[arguments.length - 1];
+        }
     }
 
     /**
@@ -149,12 +153,12 @@ public class StringFormattedMessage impl
     }
 
     /**
-     * Always returns null.
+     * Return the throwable passed to the Message.
      *
-     * @return null
+     * @return the Throwable.
      */
     @Override
     public Throwable getThrowable() {
-        return null;
+        return throwable;
     }
 }

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatMessageTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatMessageTest.java?rev=1487890&r1=1487889&r2=1487890&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatMessageTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatMessageTest.java
Thu May 30 15:14:54 2013
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.message
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 /**
  *
@@ -50,4 +51,15 @@ public class MessageFormatMessageTest {
         final String expected = "Test message Apache";
         assertEquals(expected, result);
     }
+
+    @Test
+    public void testException() {
+        final String testMsg = "Test message {0}";
+        final MessageFormatMessage msg = new MessageFormatMessage(testMsg, "Apache", new
NullPointerException("Null"));
+        final String result = msg.getFormattedMessage();
+        final String expected = "Test message Apache";
+        assertEquals(expected, result);
+        Throwable t = msg.getThrowable();
+        assertNotNull("No Throwable", t);
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StringFormattedMessageTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StringFormattedMessageTest.java?rev=1487890&r1=1487889&r2=1487890&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StringFormattedMessageTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StringFormattedMessageTest.java
Thu May 30 15:14:54 2013
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.message
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 /**
  *
@@ -49,4 +50,15 @@ public class StringFormattedMessageTest 
         final String expected = "Test message Apache";
         assertEquals(expected, result);
     }
+
+    @Test
+    public void testException() {
+        final String testMsg = "Test message {0}";
+        final MessageFormatMessage msg = new MessageFormatMessage(testMsg, "Apache", new
NullPointerException("Null"));
+        final String result = msg.getFormattedMessage();
+        final String expected = "Test message Apache";
+        assertEquals(expected, result);
+        Throwable t = msg.getThrowable();
+        assertNotNull("No Throwable", t);
+    }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1487890&r1=1487889&r2=1487890&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Thu May 30 15:14:54 2013
@@ -22,6 +22,10 @@
   </properties>
   <body>
     <release version="2.0-beta7" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-242" dev="rgoers" type="fix">
+        StringFormattedMessage and MessageFormatMessage now will accept a Throwable as their
last argument and
+        pass it on.
+      </action>
       <action issue="LOG4J2-243" dev="rgoers" type="update">
         Allow custom LogEventFactories.
       </action>



Mime
View raw message