Repository: logging-log4j2 Updated Branches: refs/heads/master 5b4f3db4f -> 5e92ed9fa
[LOG4J2-1961] Reconfigure breaks DirectWriteRolloverStrategy. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5e92ed9f Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5e92ed9f Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5e92ed9f Branch: refs/heads/master Commit: 5e92ed9fad60b6034676ac74f7ac4f3c072eb315 Parents: 5b4f3db Author: Christian Vent <[email protected]> Authored: Thu Jul 6 03:04:28 2017 -0700 Committer: Gary Gregory <[email protected]> Committed: Thu Jul 6 03:04:28 2017 -0700 ---------------------------------------------------------------------- .../rolling/DirectWriteRolloverStrategy.java | 2 +- ...gAppenderDirectWriteWithReconfigureTest.java | 70 ++++++++++++++++++++ .../log4j-rolling-direct-reconfigure.xml | 47 +++++++++++++ src/changes/changes.xml | 3 + 4 files changed, 121 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5e92ed9f/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java index 538a895..27d73c6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java @@ -342,7 +342,7 @@ public class DirectWriteRolloverStrategy extends AbstractRolloverStrategy implem LOGGER.trace("DirectWriteRolloverStrategy.purge() took {} milliseconds", durationMillis); } Action compressAction = null; - final String sourceName = currentFileName; + final String sourceName = getCurrentFileName(manager); String compressedName = sourceName; currentFileName = null; nextIndex = fileIndex + 1; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5e92ed9f/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java new file mode 100644 index 0000000..793d746 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithReconfigureTest.java @@ -0,0 +1,70 @@ +/* + * 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.appender.rolling; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.net.URI; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.RuleChain; + +/** + * + */ +public class RollingAppenderDirectWriteWithReconfigureTest { + + private static final String CONFIG = "log4j-rolling-direct-reconfigure.xml"; + + private static final String DIR = "target/rolling-direct-reconfigure"; + + public static LoggerContextRule loggerContextRule = LoggerContextRule + .createShutdownTimeoutLoggerContextRule(CONFIG); + + @Rule + public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR); + + private Logger logger; + + @Before + public void setUp() throws Exception { + this.logger = loggerContextRule.getLogger(RollingAppenderDirectWriteWithReconfigureTest.class.getName()); + } + + @Test + public void testRollingFileAppenderWithReconfigure() throws Exception { + logger.debug("Before reconfigure"); + + @SuppressWarnings("resource") // managed by the rule. + final LoggerContext context = loggerContextRule.getLoggerContext(); + context.setConfigLocation(new URI(CONFIG)); + context.reconfigure(); + + Thread.sleep(1000); + + logger.debug("After reconfigure"); + + final File dir = new File(DIR); + assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0); + final File[] files = dir.listFiles(); + assertNotNull(files); + assertThat(dir.listFiles().length, is(equalTo(2))); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5e92ed9f/log4j-core/src/test/resources/log4j-rolling-direct-reconfigure.xml ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/resources/log4j-rolling-direct-reconfigure.xml b/log4j-core/src/test/resources/log4j-rolling-direct-reconfigure.xml new file mode 100644 index 0000000..0b111d0 --- /dev/null +++ b/log4j-core/src/test/resources/log4j-rolling-direct-reconfigure.xml @@ -0,0 +1,47 @@ +<?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 status="WARN" name="XMLConfigTest"> + <Properties> + <Property name="LOG_DIR">target/rolling-direct-reconfigure</Property> + </Properties> + <Filters> + <ThresholdFilter level="debug" /> + </Filters> + + <Appenders> + <Console name="STDOUT"> + <PatternLayout pattern="%m%n" /> + </Console> + <RollingFile name="RollingFile" filePattern="${LOG_DIR}/test1-%d{MM-dd-yy-HH-mm-ss}.log"> + <PatternLayout> + <Pattern>%d %p %C{1.} [%t] %m%n</Pattern> + </PatternLayout> + <CronTriggeringPolicy schedule="0/1 * * * * ?" /> + </RollingFile> + </Appenders> + + <Loggers> + <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false"> + <AppenderRef ref="RollingFile" /> + </Logger> + <Root level="error"> + <AppenderRef ref="STDOUT" /> + </Root> + </Loggers> + +</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5e92ed9f/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3996be8..3e563ff 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -91,6 +91,9 @@ <action issue="LOG4J2-1964" dev="ggregory" type="fix" due-to="Pierrick HYMBERT"> Dynamic reconfiguration does not work for filePattern of RollingFile. </action> + <action issue="LOG4J2-1961" dev="ggregory" type="fix" due-to="Christian Vent"> + Reconfigure breaks DirectWriteRolloverStrategy. + </action> <action issue="LOG4J2-1943" dev="rgoers" type="fix"> The eventPrefix attribute was being ignored in the RFC5424Layout. </action>
