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:46:47 UTC
[logging-log4j2] branch master updated: LOG4J2-2658:
AbstractAction.reportException records a warning to the status logger
(#293)
This is an automated email from the ASF dual-hosted git repository.
ckozak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new c97591b LOG4J2-2658: AbstractAction.reportException records a warning to the status logger (#293)
c97591b is described below
commit c97591b33024cf1a5970e4755277b6e5cd597b80
Author: Carter Kozak <ck...@ckozak.net>
AuthorDate: Fri Jul 19 13:46:42 2019 -0400
LOG4J2-2658: AbstractAction.reportException records a warning to the status logger (#293)
---
.../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 633d4bc..43d5f37 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 daa8492..4c5e2fc 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -154,6 +154,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">