diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java index 889d702fec0..851aee25f14 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java @@ -17,16 +17,24 @@ package org.apache.logging.log4j.core; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import java.lang.reflect.Field; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; +import org.apache.logging.log4j.core.util.ReflectionUtil; +import org.apache.logging.log4j.test.junit.SetTestProperty; import org.junit.jupiter.api.Test; +@SetTestProperty(key = "log4j2.is.webapp", value = "false") @LoggerContextSource("log4j-test3.xml") class ShutdownDisabledTest { @Test - void testShutdownFlag(final Configuration config) { + void testShutdownFlag(final Configuration config, final LoggerContext ctx) throws NoSuchFieldException { + Field shutdownCallback = LoggerContext.class.getDeclaredField("shutdownCallback"); + Object fieldValue = ReflectionUtil.getFieldValue(shutdownCallback, ctx); assertFalse(config.isShutdownHookEnabled(), "Shutdown hook is enabled"); + assertNull(fieldValue, "Shutdown callback is null"); } } diff --git a/log4j-core-test/src/test/resources/log4j-test3.xml b/log4j-core-test/src/test/resources/log4j-test3.xml index cef870f34b1..ca2287d5828 100644 --- a/log4j-core-test/src/test/resources/log4j-test3.xml +++ b/log4j-core-test/src/test/resources/log4j-test3.xml @@ -15,7 +15,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> -<Configuration status="OFF" name="XMLConfigTest" monitorInterval="5" shutdownHook="disable"> +<Configuration status="DEBUG" name="XMLConfigTest" monitorInterval="5" shutdownHook="disable"> <Appenders> <Console name="STDOUT"> <PatternLayout pattern="%m MDC%X%n"/> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java index 5d486c7649d..77f10593f8c 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java @@ -321,6 +321,8 @@ public void start(final Configuration config) { if (configLock.tryLock()) { try { if (this.isInitialized() || this.isStopped()) { + this.setStarting(); + setConfiguration(config); if (this.configuration.isShutdownHookEnabled()) { setUpShutdownHook(); } @@ -330,7 +332,6 @@ public void start(final Configuration config) { configLock.unlock(); } } - setConfiguration(config); LOGGER.info("{}[name={}] started with configuration {}.", getClass().getSimpleName(), getName(), config); }