Skip to content

Commit b23e9a5

Browse files
Pluto-sydvyppkarwasz
authored
Fix shutdownDisable not taking effect(#2614) (#3508)
Fix shutdownDisable not taking effect(#2614) Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com> Co-authored-by: Piotr P. Karwasz <pkarwasz-github@apache.org>
1 parent b272045 commit b23e9a5

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,24 @@
1717
package org.apache.logging.log4j.core;
1818

1919
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
2021

22+
import java.lang.reflect.Field;
2123
import org.apache.logging.log4j.core.config.Configuration;
2224
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
25+
import org.apache.logging.log4j.core.util.ReflectionUtil;
26+
import org.apache.logging.log4j.test.junit.SetTestProperty;
2327
import org.junit.jupiter.api.Test;
2428

29+
@SetTestProperty(key = "log4j2.isWebapp", value = "false")
2530
@LoggerContextSource("log4j-test3.xml")
2631
class ShutdownDisabledTest {
2732

2833
@Test
29-
void testShutdownFlag(final Configuration config) {
34+
void testShutdownFlag(final Configuration config, final LoggerContext ctx) throws NoSuchFieldException {
35+
Field shutdownCallback = LoggerContext.class.getDeclaredField("shutdownCallback");
36+
Object fieldValue = ReflectionUtil.getFieldValue(shutdownCallback, ctx);
3037
assertFalse(config.isShutdownHookEnabled(), "Shutdown hook is enabled");
38+
assertNull(fieldValue, "Shutdown callback is null");
3139
}
3240
}

log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ public void start(final Configuration config) {
321321
if (configLock.tryLock()) {
322322
try {
323323
if (this.isInitialized() || this.isStopped()) {
324+
setStarting();
325+
reconfigure(config);
324326
if (this.configuration.isShutdownHookEnabled()) {
325327
setUpShutdownHook();
326328
}
@@ -330,7 +332,6 @@ public void start(final Configuration config) {
330332
configLock.unlock();
331333
}
332334
}
333-
setConfiguration(config);
334335
LOGGER.info("{}[name={}] started with configuration {}.", getClass().getSimpleName(), getName(), config);
335336
}
336337

log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootLoggingSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ protected void loadConfiguration(final String location, final LogFile logFile, f
158158
final URL url = ResourceUtils.getURL(location);
159159
final ConfigurationSource source = getConfigurationSource(url);
160160
if (source != null) {
161-
ctx.start(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
161+
ctx.reconfigure(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
162162
}
163163
} else {
164164
final List<AbstractConfiguration> configs = new ArrayList<>();
@@ -189,9 +189,9 @@ protected void loadConfiguration(final String location, final LogFile logFile, f
189189
first = false;
190190
}
191191
if (configs.size() > 1) {
192-
ctx.start(new CompositeConfiguration(configs));
192+
ctx.reconfigure(new CompositeConfiguration(configs));
193193
} else {
194-
ctx.start(configs.get(0));
194+
ctx.reconfigure(configs.get(0));
195195
}
196196
}
197197
} catch (Exception ex) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="added">
6+
<issue id="2614" link="https://github.com/apache/logging-log4j2/issues/2614"/>
7+
<description format="asciidoc">
8+
Fix shutdownDisable configuration does not take effect
9+
</description>
10+
</entry>

0 commit comments

Comments
 (0)