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/02/22 21:07:31 UTC
[logging-log4j2] branch release-2.x updated: LOG4J2-2039 -
RolloverFails when file matches pattern but index is too large.
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 da6d0e2 LOG4J2-2039 - RolloverFails when file matches pattern but index is too large.
da6d0e2 is described below
commit da6d0e2dcb882273f576459d6fc978c58c50e38a
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sat Feb 22 14:07:15 2020 -0700
LOG4J2-2039 - RolloverFails when file matches pattern but index is too large.
---
.../core/appender/rolling/AbstractRolloverStrategy.java | 9 +++++++--
.../core/appender/rolling/RollingAppenderCountTest.java | 15 ++++++++++++---
src/changes/changes.xml | 3 +++
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java
index 6cab5fa..6705fc8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java
@@ -133,8 +133,13 @@ public abstract class AbstractRolloverStrategy implements RolloverStrategy {
for (final Path entry: stream) {
final Matcher matcher = pattern.matcher(entry.toFile().getName());
if (matcher.matches() && !entry.equals(current)) {
- final Integer index = Integer.parseInt(matcher.group(1));
- eligibleFiles.put(index, entry);
+ try {
+ final Integer index = Integer.parseInt(matcher.group(1));
+ eligibleFiles.put(index, entry);
+ } catch (NumberFormatException ex) {
+ LOGGER.debug("Ignoring file {} which matches pattern but the index is invalid.",
+ entry.toFile().getName());
+ }
}
}
} catch (final IOException ioe) {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCountTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCountTest.java
index 4852078..fd7c408 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCountTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCountTest.java
@@ -30,6 +30,7 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.Objects;
import static org.junit.Assert.assertEquals;
@@ -39,9 +40,11 @@ import static org.junit.Assert.assertEquals;
*/
public class RollingAppenderCountTest {
+ private static final String SOURCE = "src/test/resources/__files";
private static final String DIR = "target/rolling_count";
private static final String CONFIG = "log4j-rolling-count.xml";
- private static final String FILENAME = "rolling_test.log";
+ private static final String FILENAME = "onStartup.log";
+ private static final String TARGET = "rolling_test.log.";
private Logger logger;
@@ -59,7 +62,7 @@ public class RollingAppenderCountTest {
@BeforeClass
public static void beforeClass() throws Exception {
- if (Files.exists(Paths.get("target/onStartup"))) {
+ if (Files.exists(Paths.get(DIR))) {
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(DIR))) {
for (final Path path : directoryStream) {
Files.delete(path);
@@ -67,12 +70,18 @@ public class RollingAppenderCountTest {
Files.delete(Paths.get(DIR));
}
}
+ File dir = new File(DIR);
+ if (!dir.exists()) {
+ Files.createDirectory(new File(DIR).toPath());
+ }
+ Path target = Paths.get(DIR, TARGET + System.currentTimeMillis());
+ Files.copy(Paths.get(SOURCE, FILENAME), target, StandardCopyOption.COPY_ATTRIBUTES);
}
@AfterClass
public static void afterClass() throws Exception {
int count = Objects.requireNonNull(new File(DIR).listFiles()).length;
- assertEquals("Expected 16 files, got " + count, 16, count);
+ assertEquals("Expected 17 files, got " + count, 17, count);
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(DIR))) {
for (final Path path : directoryStream) {
Files.delete(path);
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b5aff20..95e3532 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,6 +30,9 @@
- "remove" - Removed
-->
<release version="2.13.1" date="2019-MM-DD" description="GA Release 2.13.1">
+ <action issue="LOG4J2-2039" dev="rgoers" type="fix">
+ RolloverFails when file matches pattern but index is too large.
+ </action>
<action issue="LOG4J2-2784" dev="rgoers" type="fix">
Counter stuck at 10 and overwriting files when leading zeros used in the file pattern count.
</action>