You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2020/09/12 17:33:11 UTC

[logging-log4j2] branch release-2.x updated (e062646 -> 8865f6a)

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

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


    from e062646  Migrate more tests to JUnit 5
     new 1aabc2e  LOG4J2-2919 Call ReliabilityStrategy's beforeStopAppenders() method before stopping AsyncAppenders to avoid errors caused by logging with AsyncAppender while system is reconfiguring Submitted by: gengyuanzhe <ge...@gmail.com>
     new 064ddbc  Add tests for LOG4J2-1121 and LOG4J2-2919
     new 8865f6a  Add changelog entry for LOG4J2-2919

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../log4j/core/config/AbstractConfiguration.java   |  12 +--
 .../log4j/core/config/MockReliabilityStrategy.java | 105 +++++++++++++++++++++
 ...utputTest.java => ReliabilityStrategyTest.java} |  38 +++++---
 ...ppenderTest.xml => ReliabilityStrategyTest.xml} |  17 ++--
 src/changes/changes.xml                            |   3 +
 5 files changed, 148 insertions(+), 27 deletions(-)
 create mode 100644 log4j-core/src/test/java/org/apache/logging/log4j/core/config/MockReliabilityStrategy.java
 copy log4j-core/src/test/java/org/apache/logging/log4j/core/config/{FileOutputTest.java => ReliabilityStrategyTest.java} (51%)
 copy log4j-core/src/test/resources/{HttpAppenderTest.xml => ReliabilityStrategyTest.xml} (75%)


[logging-log4j2] 02/03: Add tests for LOG4J2-1121 and LOG4J2-2919

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 064ddbc3a0af9505c3e9041729e8acbc990c3a81
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sat Sep 12 12:25:57 2020 -0500

    Add tests for LOG4J2-1121 and LOG4J2-2919
    
    Signed-off-by: Matt Sicker <bo...@gmail.com>
---
 .../log4j/core/config/MockReliabilityStrategy.java | 105 +++++++++++++++++++++
 .../log4j/core/config/ReliabilityStrategyTest.java |  51 ++++++++++
 .../src/test/resources/ReliabilityStrategyTest.xml |  32 +++++++
 3 files changed, 188 insertions(+)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MockReliabilityStrategy.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MockReliabilityStrategy.java
new file mode 100644
index 0000000..5e5e87c
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MockReliabilityStrategy.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.config;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LifeCycle;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.util.Supplier;
+import org.opentest4j.MultipleFailuresError;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+/**
+ * Mock object for validating the behavior of a configuration interacting with ReliabilityStrategy.
+ */
+public class MockReliabilityStrategy implements ReliabilityStrategy {
+
+    private final LoggerConfig config;
+    private final List<AssertionError> errors = Collections.synchronizedList(new ArrayList<>());
+
+    public MockReliabilityStrategy(final LoggerConfig config) {
+        this.config = config;
+    }
+
+    @Override
+    public void log(
+            final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn, final Marker marker,
+            final Level level, final Message data, final Throwable t) {
+        config.log(loggerName, fqcn, marker, level, data, t);
+    }
+
+    @Override
+    public void log(
+            final Supplier<LoggerConfig> reconfigured, final String loggerName, final String fqcn,
+            final StackTraceElement location, final Marker marker, final Level level, final Message data, final Throwable t) {
+        config.log(loggerName, fqcn, location, marker, level, data, t);
+    }
+
+    @Override
+    public void log(final Supplier<LoggerConfig> reconfigured, final LogEvent event) {
+        config.log(event);
+    }
+
+    @Override
+    public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) {
+        return config;
+    }
+
+    @Override
+    public void afterLogEvent() {
+        // no-op
+    }
+
+    @Override
+    public void beforeStopAppenders() {
+        checkState(LifeCycle.State.STOPPED, config);
+        for (final Appender appender : config.getAppenders().values()) {
+            checkState(LifeCycle.State.STARTED, appender);
+        }
+    }
+
+    @Override
+    public void beforeStopConfiguration(final Configuration configuration) {
+        checkState(LifeCycle.State.STOPPING, configuration);
+        checkState(LifeCycle.State.STARTED, config);
+    }
+
+    void rethrowAssertionErrors() {
+        synchronized (errors) {
+            if (!errors.isEmpty()) {
+                throw new MultipleFailuresError(null, errors);
+            }
+        }
+    }
+
+    private void checkState(final LifeCycle.State expected, final LifeCycle object) {
+        try {
+            assertSame(expected, object.getState(), () -> "Expected state " + expected + " for LifeCycle object " + object);
+        } catch (final AssertionError e) {
+            errors.add(e);
+        }
+    }
+}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReliabilityStrategyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReliabilityStrategyTest.java
new file mode 100644
index 0000000..0b68e27
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReliabilityStrategyTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.config;
+
+import org.apache.logging.log4j.core.appender.AsyncAppender;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class ReliabilityStrategyTest {
+
+    @BeforeAll
+    static void setUp() {
+        System.setProperty("log4j2.reliabilityStrategy", MockReliabilityStrategy.class.getName());
+    }
+
+    @AfterAll
+    static void tearDown() {
+        System.clearProperty("log4j2.reliabilityStrategy");
+    }
+
+    @Test
+    @LoggerContextSource("ReliabilityStrategyTest.xml")
+    void beforeStopAppendersCalledBeforeAsyncAppendersStopped(@Named final AsyncAppender async, final Configuration config) {
+        assertTrue(async.isStarted());
+        final MockReliabilityStrategy reliabilityStrategy =
+                (MockReliabilityStrategy) config.getRootLogger().getReliabilityStrategy();
+        config.stop();
+        assertTrue(async.isStopped());
+        reliabilityStrategy.rethrowAssertionErrors();
+    }
+}
diff --git a/log4j-core/src/test/resources/ReliabilityStrategyTest.xml b/log4j-core/src/test/resources/ReliabilityStrategyTest.xml
new file mode 100644
index 0000000..a13ea9b
--- /dev/null
+++ b/log4j-core/src/test/resources/ReliabilityStrategyTest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements. See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache license, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License. You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the license for the specific language governing permissions and
+  ~ limitations under the license.
+  -->
+<Configuration name="ReliabilityStrategyTest" status="OFF">
+  <Appenders>
+    <List name="list">
+      <PatternLayout pattern="%m"/>
+    </List>
+    <Async name="async">
+      <AppenderRef ref="list"/>
+    </Async>
+  </Appenders>
+  <Loggers>
+    <Root level="DEBUG">
+      <AppenderRef ref="async"/>
+    </Root>
+  </Loggers>
+</Configuration>


[logging-log4j2] 01/03: LOG4J2-2919 Call ReliabilityStrategy's beforeStopAppenders() method before stopping AsyncAppenders to avoid errors caused by logging with AsyncAppender while system is reconfiguring Submitted by: gengyuanzhe

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1aabc2e3048784f5fb28a55167c93332f3bb2e8e
Author: gengyuanzhe <ge...@gmail.com>
AuthorDate: Tue Sep 8 01:02:14 2020 +0800

    LOG4J2-2919
    Call ReliabilityStrategy's beforeStopAppenders() method before stopping AsyncAppenders
    to avoid errors caused by logging with AsyncAppender while system is reconfiguring
    Submitted by: gengyuanzhe <ge...@gmail.com>
---
 .../logging/log4j/core/config/AbstractConfiguration.java     | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index 42e9940..9cae60d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -369,6 +369,12 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
             asyncLoggerConfigDisruptor.stop(timeout, timeUnit);
         }
 
+        LOGGER.trace("{} notifying ReliabilityStrategies that appenders will be stopped.", cls);
+        for (final LoggerConfig loggerConfig : loggerConfigs.values()) {
+            loggerConfig.getReliabilityStrategy().beforeStopAppenders();
+        }
+        root.getReliabilityStrategy().beforeStopAppenders();
+
         // Stop the appenders in reverse order in case they still have activity.
         final Appender[] array = appenders.values().toArray(new Appender[appenders.size()]);
         final List<Appender> async = getAsyncAppenders(array);
@@ -384,12 +390,6 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
             }
         }
 
-        LOGGER.trace("{} notifying ReliabilityStrategies that appenders will be stopped.", cls);
-        for (final LoggerConfig loggerConfig : loggerConfigs.values()) {
-            loggerConfig.getReliabilityStrategy().beforeStopAppenders();
-        }
-        root.getReliabilityStrategy().beforeStopAppenders();
-
         LOGGER.trace("{} stopping remaining Appenders.", cls);
         int appenderCount = 0;
         for (int i = array.length - 1; i >= 0; --i) {


[logging-log4j2] 03/03: Add changelog entry for LOG4J2-2919

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8865f6aece01e3cd71a1f92f215d2e32479e1257
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sat Sep 12 12:32:45 2020 -0500

    Add changelog entry for LOG4J2-2919
---
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3c33ef7..c5c4fc5 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,6 +30,9 @@
          - "remove" - Removed
     -->
     <release version="2.14.0" date="2020-MM-DD" description="GA Release 2.14.0">
+      <action issue="LOG4J2-2919" dev="mattsicker" type="fix" due-to="Geng Yuanzhe">
+        Call ReliabilityStrategy's beforeStopAppenders() method before stopping AsyncAppender.
+      </action>
       <action issue="LOG4J2-2892" dev="rgoers" type="update" due-to="Jakub Lukes">
         Allow GelfLayout to produce newline delimited events.
       </action>