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 2021/11/21 23:35:26 UTC
[logging-log4j2] branch master updated: LOG4J2-3194 - Allow fractional attributes for size attribute of SizeBsaedTriggeringPolicy.
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 6b619ca LOG4J2-3194 - Allow fractional attributes for size attribute of SizeBsaedTriggeringPolicy.
6b619ca is described below
commit 6b619cacf4caa24ad484be1e7cca341c51ba4b76
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Nov 21 16:35:18 2021 -0700
LOG4J2-3194 - Allow fractional attributes for size attribute of SizeBsaedTriggeringPolicy.
---
.../log4j/core/appender/rolling/FileSize.java | 12 ++++++------
.../log4j/core/appender/rolling/FileSizeTest.java | 22 ++++++++++++++++++++++
src/changes/changes.xml | 21 ++++++++++++---------
src/site/asciidoc/manual/appenders.adoc | 2 ++
4 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java
index f95dc8e..fc3457e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileSize.java
@@ -61,20 +61,20 @@ public final class FileSize {
if (matcher.matches()) {
try {
// Get double precision value
- final long value = NumberFormat.getNumberInstance(Locale.ROOT).parse(
- matcher.group(1)).longValue();
+ final double value = NumberFormat.getNumberInstance(Locale.ROOT).parse(
+ matcher.group(1)).doubleValue();
// Get units specified
final String units = matcher.group(3);
if (units.isEmpty()) {
- return value;
+ return (long) value;
} else if (units.equalsIgnoreCase("K")) {
- return value * KB;
+ return (long) (value * KB);
} else if (units.equalsIgnoreCase("M")) {
- return value * MB;
+ return (long) (value * MB);
} else if (units.equalsIgnoreCase("G")) {
- return value * GB;
+ return (long) (value * GB);
} else {
LOGGER.error("FileSize units not recognized: " + string);
return defaultValue;
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/FileSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/FileSizeTest.java
index 35e2199..0723591 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/FileSizeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/FileSizeTest.java
@@ -17,6 +17,8 @@
package org.apache.logging.log4j.core.appender.rolling;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.*;
@@ -34,4 +36,24 @@ public class FileSizeTest {
value = FileSize.parse("10 KB", 0);
assertEquals(EXPECTED, value, "unexpected value " + value);
}
+
+ @ParameterizedTest(name = "[{index}] \"{0}\" -> {1}")
+ @CsvSource(delimiter = ':', value = {
+ "10:10",
+ "10KB:10240",
+ "10 KB:10240",
+ "10 kb:10240",
+ " 10 kb :10240",
+ "0.1 MB:104857",
+ "1 MB:1048576",
+ "10 MB:10485760",
+ "10.45 MB:10957619",
+ "10.75 MB:11272192",
+ "1,000 KB:1024000",
+ "1 GB:1073741824",
+ "0.51 GB:547608330"
+ })
+ void testValidFileSizes(String expr, long expected) {
+ assertEquals(expected, FileSize.parse(expr, 0));
+ }
}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b904fa2..9398ff9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -170,6 +170,9 @@
</release>
<release version="2.15.0" date="2021-MM-DD" description="GA Release 2.15.0">
<!-- ADDS -->
+ <action issue="LOG4J2-3194" dev="rgoers" type="add" due-to="markuss">
+ Allow fractional attributes for size attribute of SizeBsaedTriggeringPolicy.
+ </action>
<action issue="LOG4J2-3189" dev="ckozak" type="add">
Improve NameAbbreviator worst-case performance.
</action>
@@ -243,6 +246,15 @@
based on performance improvements in modern Java releases.
</action>
<!-- FIXES -->
+ <action issue="LOG4J2-3114" dev="rgoers" type="fix" due-to="Barnabas Bodnar">
+ Enable immediate flush on RollingFileAppender when buffered i/o is not enabled.
+ </action>
+ <action issue="LOG4J2-3168" dev="rgoers" type="fix" due-to="Benjamin Wöster">
+ Fix bug when file names contain regex characters.
+ </action>
+ <action issue="LOG4J2-3110" dev="rgoers" type="fix" due-to="Arturo Bernal">
+ Fix the number of {}-placeholders in the string literal argument does not match the number of other arguments to the logging call.
+ </action>
<action issue="LOG4J2-3060" dev="vy" type="fix" due-to=" Nikita Mikhailov">
Fix thread-safety issues in DefaultErrorHandler.
</action>
@@ -2969,15 +2981,6 @@
<action issue="LOG4J2-1384" dev="ggregory" type="update">
Update Apache Commons CSV from 1.2 to 1.3.
</action>
- <action issue="LOG4J2-3114" dev="rgoers" type="fix" due-to="Barnabas Bodnar">
- Enable immediate flush on RollingFileAppender when buffered i/o is not enabled.
- </action>
- <action issue="LOG4J2-3168" dev="rgoers" type="fix" due-to="Benjamin Wöster">
- Fix bug when file names contain regex characters.
- </action>
- <action issue="LOG4J2-3110" dev="rgoers" type="fix" due-to="Arturo Bernal">
- Fix the number of {}-placeholders in the string literal argument does not match the number of other arguments to the logging call.
- </action>
<action issue="LOG4J2-1372" dev="rgoers" type="fix" due-to="Kamal Mettananda, Gary Gregory">
XMLLayout indents, but not the first child tag (Event).
</action>
diff --git a/src/site/asciidoc/manual/appenders.adoc b/src/site/asciidoc/manual/appenders.adoc
index b6984ed..b52b972 100644
--- a/src/site/asciidoc/manual/appenders.adoc
+++ b/src/site/asciidoc/manual/appenders.adoc
@@ -2761,6 +2761,8 @@ SizeBased Triggering Policy
The `SizeBasedTriggeringPolicy` causes a rollover once the file has reached the specified size. The size can be
specified in bytes, with the suffix KB, MB or GB, for example `20MB`.
+size.The size may also contain a fractional value such as `1.5 MB`. The size is evaluated
+using the Java root Locale so a period must always be used for the fractional unit.
When combined with a time based triggering policy the file pattern must contain a `%i`
otherwise the target file will be overwritten on every rollover as the SizeBased Triggering Policy
will not cause the timestamp value in the file name to change. When used without a time based