logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1518012 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java src/changes/changes.xml
Date Tue, 27 Aug 2013 22:07:36 GMT
Author: rpopma
Date: Tue Aug 27 22:07:35 2013
New Revision: 1518012

URL: http://svn.apache.org/r1518012
Log:
LOG4J2-310 fixed issue where SMTPAppender does not send mails with error or fatal level without
prior info event

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java?rev=1518012&r1=1518011&r2=1518012&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
Tue Aug 27 22:07:35 2013
@@ -136,9 +136,8 @@ public class SMTPManager extends Abstrac
         }
         try {
             final LogEvent[] priorEvents = buffer.removeAll();
-            if (priorEvents == null || priorEvents.length == 0) {
-                return; // nothing to do, another thread already took all events
-            }
+            // LOG4J-310: log appendEvent even if priorEvents is empty
+            
             final byte[] rawBytes = formatContentToBytes(priorEvents, appendEvent, layout);
 
             final String contentType = layout.getContentType();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java?rev=1518012&r1=1518011&r2=1518012&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
Tue Aug 27 22:07:35 2013
@@ -16,11 +16,17 @@
  */
 package org.apache.logging.log4j.core.appender;
 
+import static org.junit.Assert.*;
+
+import java.util.Iterator;
+
 import javax.mail.Address;
 import javax.mail.Message;
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetAddress;
 
+import org.apache.logging.dumbster.smtp.SimpleSmtpServer;
+import org.apache.logging.dumbster.smtp.SmtpMessage;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Logger;
@@ -29,15 +35,6 @@ import org.apache.logging.log4j.core.hel
 import org.apache.logging.log4j.core.net.MimeMessageBuilder;
 import org.junit.Test;
 
-import org.apache.logging.dumbster.smtp.SimpleSmtpServer;
-import org.apache.logging.dumbster.smtp.SmtpMessage;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertArrayEquals;
-
 public class SMTPAppenderTest {
 
     private static final String HOST = "localhost";
@@ -55,12 +52,13 @@ public class SMTPAppenderTest {
         Address[] array = null;
         final Address addr = InternetAddress.getLocalAddress(null);
         if (addr != null) {
-            array = new Address[] {addr};
+            array = new Address[] { addr };
         }
         assertArrayEquals(array, builder.getMimeMessage().getFrom());
 
         builder.setFrom(address);
-        assertArrayEquals(new Address[] { new InternetAddress(address) }, builder.getMimeMessage().getFrom());
+        assertArrayEquals(new Address[] { new InternetAddress(address) },
+                builder.getMimeMessage().getFrom());
     }
 
     @Test
@@ -74,7 +72,8 @@ public class SMTPAppenderTest {
         assertNull(builder.getMimeMessage().getReplyTo());
 
         builder.setReplyTo(addresses);
-        assertArrayEquals(InternetAddress.parse(addresses), builder.getMimeMessage().getReplyTo());
+        assertArrayEquals(InternetAddress.parse(addresses), builder
+                .getMimeMessage().getReplyTo());
     }
 
     @Test
@@ -82,13 +81,16 @@ public class SMTPAppenderTest {
         final MimeMessageBuilder builder = new MimeMessageBuilder(null);
         final String addresses = "testing1@example.com,testing2@example.com";
 
-        assertNull(builder.getMimeMessage().getRecipients(Message.RecipientType.TO));
+        assertNull(builder.getMimeMessage().getRecipients(
+                Message.RecipientType.TO));
 
         builder.setRecipients(Message.RecipientType.TO, null);
-        assertNull(builder.getMimeMessage().getRecipients(Message.RecipientType.TO));
+        assertNull(builder.getMimeMessage().getRecipients(
+                Message.RecipientType.TO));
 
         builder.setRecipients(Message.RecipientType.TO, addresses);
-        assertArrayEquals(InternetAddress.parse(addresses), builder.getMimeMessage().getRecipients(Message.RecipientType.TO));
+        assertArrayEquals(InternetAddress.parse(addresses), builder
+                .getMimeMessage().getRecipients(Message.RecipientType.TO));
     }
 
     @Test
@@ -107,7 +109,8 @@ public class SMTPAppenderTest {
 
     @Test
     public void testCyclicBuffer() {
-        final CyclicBuffer<Integer> buffer = new CyclicBuffer<Integer>(Integer.class,
3);
+        final CyclicBuffer<Integer> buffer = new CyclicBuffer<Integer>(
+                Integer.class, 3);
 
         assertTrue(buffer.isEmpty());
         buffer.add(1);
@@ -125,12 +128,12 @@ public class SMTPAppenderTest {
         assertTrue(buffer.isEmpty());
     }
 
-
     @Test
     public void testDelivery() {
-        final SMTPAppender appender = SMTPAppender.createAppender("Test", "to@example.com",
"cc@example.com", "bcc@example.com", "from@example.com",
-            "replyTo@example.com", "Subject", null, HOST, PORT, null, null, "false", "3",
null, null,
-            "true");
+        final SMTPAppender appender = SMTPAppender.createAppender("Test",
+                "to@example.com", "cc@example.com", "bcc@example.com",
+                "from@example.com", "replyTo@example.com", "Subject", null,
+                HOST, PORT, null, null, "false", "3", null, null, "true");
         appender.start();
 
         final LoggerContext context = (LoggerContext) LogManager.getContext();
@@ -145,11 +148,14 @@ public class SMTPAppenderTest {
         root.debug("Debug message #2");
         root.debug("Debug message #3");
         root.debug("Debug message #4");
-        root.error("Error with exception", new RuntimeException("Exception message"));
+        root.error("Error with exception", new RuntimeException(
+                "Exception message"));
+        root.error("Error message #2");
 
         server.stop();
-        assertTrue(server.getReceivedEmailSize() == 1);
-        final SmtpMessage email = server.getReceivedEmail().next();
+        assertTrue(server.getReceivedEmailSize() == 2);
+        final Iterator<SmtpMessage> messages = server.getReceivedEmail();
+        final SmtpMessage email = messages.next();
 
         assertEquals("to@example.com", email.getHeaderValue("To"));
         assertEquals("cc@example.com", email.getHeaderValue("Cc"));
@@ -167,6 +173,12 @@ public class SMTPAppenderTest {
         assertTrue(body.contains("Error with exception"));
         assertTrue(body.contains("RuntimeException"));
         assertTrue(body.contains("Exception message"));
+        assertFalse(body.contains("Error message #2"));
+
+        final SmtpMessage email2 = (SmtpMessage) messages.next();
+        final String body2 = email2.getBody();
+        assertFalse(body2.contains("Debug message #4"));
+        assertFalse(body2.contains("Error with exception"));
+        assertTrue(body2.contains("Error message #2"));
     }
 }
-

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1518012&r1=1518011&r2=1518012&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Aug 27 22:07:35 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-310" dev="rpopma" type="fix" due-to="Olivier Lemasle">
+        Fixed issue where SMTPAppender did not send mails with error or fatal level without
prior info event.
+      </action>
       <action issue="LOG4J2-368" dev="rgoers" type="fix">
         Add PatternLayout constructor to Log4j 1.2 bridge for Velocity.
       </action>



Mime
View raw message