You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2019/07/19 17:47:00 UTC

[logging-log4j2] branch release-2.x updated: LOG4J2-2658: AbstractAction.reportException records a warning to the status logger (#294)

This is an automated email from the ASF dual-hosted git repository.

ckozak pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new 4ab46ab  LOG4J2-2658: AbstractAction.reportException records a warning to the status logger (#294)
4ab46ab is described below

commit 4ab46ab8d1994a550792143c4f359558777c4922
Author: Carter Kozak <ck...@ckozak.net>
AuthorDate: Fri Jul 19 13:46:56 2019 -0400

    LOG4J2-2658: AbstractAction.reportException records a warning to the status logger (#294)
---
 .../appender/rolling/action/AbstractAction.java    |  1 +
 .../rolling/action/AbstractActionTest.java         | 45 ++++++++++++++++++++++
 src/changes/changes.xml                            |  4 ++
 3 files changed, 50 insertions(+)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractAction.java
index f6a92ff..214308e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractAction.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractAction.java
@@ -101,6 +101,7 @@ public abstract class AbstractAction implements Action {
      * @param ex exception.
      */
     protected void reportException(final Exception ex) {
+        LOGGER.warn("Exception reported by action '{}'", getClass(), ex);
     }
 
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java
new file mode 100644
index 0000000..0f76119
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractActionTest.java
@@ -0,0 +1,45 @@
+package org.apache.logging.log4j.core.appender.rolling.action;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.junit.StatusLoggerRule;
+import org.apache.logging.log4j.status.StatusData;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class AbstractActionTest {
+
+    @Rule
+    public StatusLoggerRule statusLogger = new StatusLoggerRule(Level.WARN);
+
+    // Test for LOG4J2-2658
+    @Test
+    public void testExceptionsAreLoggedToStatusLogger() {
+        StatusLogger statusLogger = StatusLogger.getLogger();
+        statusLogger.clear();
+        new TestAction().run();
+        List<StatusData> statusDataList = statusLogger.getStatusData();
+        assertEquals(1, statusDataList.size());
+        StatusData statusData = statusDataList.get(0);
+        assertEquals(Level.WARN, statusData.getLevel());
+        String formattedMessage = statusData.getFormattedStatus();
+        assertTrue(formattedMessage.contains("Exception reported by action 'class org.apache." +
+                "logging.log4j.core.appender.rolling.action.AbstractActionTest$TestAction' java.io.IOException: " +
+                "failed\n\tat org.apache.logging.log4j.core.appender.rolling.action.AbstractActionTest" +
+                "$TestAction.execute(AbstractActionTest.java:"));
+    }
+
+    private static final class TestAction extends AbstractAction {
+        @Override
+        public boolean execute() {
+            this.reportException(new IOException("failed"));
+            return false;
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 24c090f..bd4fd19 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -39,6 +39,10 @@
       <action issue="LOG4J2-2657" dev="ggregory" type="update">
         Improve exception messages in the JDBC appender.
       </action>
+      <action issue="LOG4J2-2658" dev="ckozak" type="fix">
+        AbstractAction.reportException records a warning to the status logger, providing more information when file
+        based appenders fail to compress rolled data asynchronously.
+      </action>
     </release>
     <release version="2.12.0" date="2019-06-23" description="GA Release 2.12.0">
       <action issue="LOG4J2-2547" dev="rgoers" type="fix">