Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/issue 2614 #3483

Closed
wants to merge 2 commits into from
Closed
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.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");
}
}
2 changes: 1 addition & 1 deletion log4j-core-test/src/test/resources/log4j-test3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
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()) {
this.setStarting();
setConfiguration(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