Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.isWebapp", 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ public void start(final Configuration config) {
if (configLock.tryLock()) {
try {
if (this.isInitialized() || this.isStopped()) {
setStarting();
reconfigure(config);
if (this.configuration.isShutdownHookEnabled()) {
setUpShutdownHook();
}
Expand All @@ -330,7 +332,6 @@ public void start(final Configuration config) {
configLock.unlock();
}
}
setConfiguration(config);
LOGGER.info("{}[name={}] started with configuration {}.", getClass().getSimpleName(), getName(), config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected void loadConfiguration(final String location, final LogFile logFile, f
final URL url = ResourceUtils.getURL(location);
final ConfigurationSource source = getConfigurationSource(url);
if (source != null) {
ctx.start(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
ctx.reconfigure(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
}
} else {
final List<AbstractConfiguration> configs = new ArrayList<>();
Expand Down Expand Up @@ -189,9 +189,9 @@ protected void loadConfiguration(final String location, final LogFile logFile, f
first = false;
}
if (configs.size() > 1) {
ctx.start(new CompositeConfiguration(configs));
ctx.reconfigure(new CompositeConfiguration(configs));
} else {
ctx.start(configs.get(0));
ctx.reconfigure(configs.get(0));
}
}
} catch (Exception ex) {
Expand Down
10 changes: 10 additions & 0 deletions src/changelog/.2.x.x/3508_LoggerContext_shutdownDisable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="added">
<issue id="2614" link="https://github.com/apache/logging-log4j2/issues/2614"/>
<description format="asciidoc">
Fix shutdownDisable configuration does not take effect
</description>
</entry>