You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2020/07/31 04:20:06 UTC
[logging-log4j2] branch release-2.x updated: LOG4J2-2883 - When
When using DirectFileRolloverStrategy the file pattern was not being
recalculated on size based rollover after a time based rollover had
occurred.
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 1a6f6b4 LOG4J2-2883 - When When using DirectFileRolloverStrategy the file pattern was not being recalculated on size based rollover after a time based rollover had occurred.
1a6f6b4 is described below
commit 1a6f6b4a2c2bebb8a1ff32479d33ca8536a9c573
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Thu Jul 30 21:19:51 2020 -0700
LOG4J2-2883 - When When using DirectFileRolloverStrategy the file pattern was not being recalculated on size based rollover after a time based rollover had occurred.
---
.../core/appender/rolling/PatternProcessor.java | 1 +
.../RollingDirectSizeTimeNewDirectoryTest.java | 85 ++++++++++++++++++++++
.../log4j-rolling-size-time-new-directory.xml | 42 +++++++++++
src/changes/changes.xml | 4 +
4 files changed, 132 insertions(+)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
index 1fd8012..0bfa3d1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
@@ -227,6 +227,7 @@ public class PatternProcessor {
public void updateTime() {
if (nextFileTime != 0 || !isTimeBased) {
prevFileTime = nextFileTime;
+ currentFileTime = 0;
}
}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java
new file mode 100644
index 0000000..a9d3ee5
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+
+import java.io.File;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.sort;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests
+ */
+public class RollingDirectSizeTimeNewDirectoryTest {
+ private static final String CONFIG = "log4j-rolling-size-time-new-directory.xml";
+
+ private static final String DIR = "target/rolling-size-time-new-directory";
+
+ 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(RollingDirectSizeTimeNewDirectoryTest.class.getName());
+ }
+
+
+ @Test
+ public void streamClosedError() throws Exception {
+ for (int i = 0; i < 1000; i++) {
+ logger.info("nHq6p9kgfvWfjzDRYbZp");
+ }
+ Thread.sleep(1500);
+ for (int i = 0; i < 1000; i++) {
+ logger.info("nHq6p9kgfvWfjzDRYbZp");
+ }
+
+ File tempDirectoryAsFile = new File(DIR);
+ File[] loggingFolders = tempDirectoryAsFile.listFiles();
+ assertNotNull(loggingFolders);
+ // Check if two folders were created
+ assertTrue("Not enough directories created", loggingFolders.length >= 2);
+ for (File dir : loggingFolders) {
+ File[] files = dir.listFiles();
+ assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0);
+ if (files.length < 3) {
+ System.out.println("Only " + files.length + " files created in " + dir.toString());
+ for (File logFile : files) {
+ System.out.println("File name: " + logFile.getName() + " size: " + logFile.length());
+ }
+ fail();
+ }
+
+ }
+ }
+}
diff --git a/log4j-core/src/test/resources/log4j-rolling-size-time-new-directory.xml b/log4j-core/src/test/resources/log4j-rolling-size-time-new-directory.xml
new file mode 100644
index 0000000..883bba0
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-size-time-new-directory.xml
@@ -0,0 +1,42 @@
+<?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="logDir">target/rolling-size-time-new-directory</Property>
+ </Properties>
+
+ <Appenders>
+ <RollingFile name="RollingFile" filePattern="${logDir}/%d{yyyy_MM_dd-mm-ss}/messages-$${date:yyyy_MM_dd_HH_mm_ss_SSS}.log">
+ <PatternLayout>
+ <Pattern>%d{MM-dd-yy-HH-mm-ss} %p %C{1.} [%t] %m%n</Pattern>
+ </PatternLayout>
+ <Policies>
+ <TimeBasedTriggeringPolicy />
+ <SizeBasedTriggeringPolicy size="5KB"/>
+ </Policies>
+ </RollingFile>
+ </Appenders>
+
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="RollingFile"/>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fbeceb0..8270218 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,6 +30,10 @@
- "remove" - Removed
-->
<release version="2.14.0" date="2020-MM-DD" description="GA Release 2.14.0">
+ <action issue="LOG4J2-2883" dev="rgoers" type="fix">
+ When using DirectFileRolloverStrategy the file pattern was not being recalculated on
+ size based rollover after a time based rollover had occurred.
+ </action>
<action issue="LOG4J2-2875" dev="rgoers" type="fix">
Rollover was failing to create directories when using a DirectFileeRolloverStrategy.
</action>