From 4884ac45a37ba08e0d8679811d8ce94bd5b18089 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sat, 30 Mar 2024 23:12:09 +0100 Subject: [PATCH 01/10] Move SLF4J dependencies to SLF4J-related modules --- log4j-core-its/pom.xml | 6 ------ log4j-core-test/pom.xml | 5 ----- log4j-core/pom.xml | 7 ------- log4j-mongodb3/pom.xml | 5 ----- log4j-mongodb4/pom.xml | 5 ----- log4j-parent/pom.xml | 7 ------- log4j-perf-test/pom.xml | 12 ++++++++++++ log4j-slf4j-impl/pom.xml | 7 +++---- log4j-slf4j2-impl/pom.xml | 14 ++++++++++++++ log4j-to-slf4j/pom.xml | 13 +++++++++++++ 10 files changed, 42 insertions(+), 39 deletions(-) diff --git a/log4j-core-its/pom.xml b/log4j-core-its/pom.xml index 8564c7c0fca..3163e3248e9 100644 --- a/log4j-core-its/pom.xml +++ b/log4j-core-its/pom.xml @@ -153,12 +153,6 @@ logback-classic test - - - org.slf4j - slf4j-api - test - diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml index ac718f0e72b..f005dc8a956 100644 --- a/log4j-core-test/pom.xml +++ b/log4j-core-test/pom.xml @@ -317,11 +317,6 @@ plexus-utils test - - org.slf4j - slf4j-api - test - com.github.tomakehurst diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml index 0f9429a41e4..c5832adac41 100644 --- a/log4j-core/pom.xml +++ b/log4j-core/pom.xml @@ -201,13 +201,6 @@ runtime true - - - org.slf4j - slf4j-api - runtime - true - diff --git a/log4j-mongodb3/pom.xml b/log4j-mongodb3/pom.xml index 010879ed586..6efde08146f 100644 --- a/log4j-mongodb3/pom.xml +++ b/log4j-mongodb3/pom.xml @@ -161,11 +161,6 @@ junit-jupiter-engine ${junit-jupiter.version} - - org.slf4j - slf4j-nop - ${slf4j.version} - diff --git a/log4j-mongodb4/pom.xml b/log4j-mongodb4/pom.xml index ad7395f1175..f8b055f7995 100644 --- a/log4j-mongodb4/pom.xml +++ b/log4j-mongodb4/pom.xml @@ -153,11 +153,6 @@ junit-jupiter-engine ${junit-jupiter.version} - - org.slf4j - slf4j-nop - ${slf4j.version} - diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml index 774e3f92b18..816bcf41847 100644 --- a/log4j-parent/pom.xml +++ b/log4j-parent/pom.xml @@ -135,7 +135,6 @@ 6.0.0 4.13.5 3.5.1 - 2.0.9 2.7.18 5.3.33 2.0.3 @@ -909,12 +908,6 @@ ${plexus-utils.version} - - org.slf4j - slf4j-api - ${slf4j.version} - - org.springframework.boot spring-boot diff --git a/log4j-perf-test/pom.xml b/log4j-perf-test/pom.xml index 500a36bc15a..01e1d883970 100644 --- a/log4j-perf-test/pom.xml +++ b/log4j-perf-test/pom.xml @@ -41,8 +41,20 @@ 9 [9, ) true + + 2.0.9 + + + + org.slf4j + slf4j-api + ${slf4j2.version} + + + + org.openjdk.jmh diff --git a/log4j-slf4j-impl/pom.xml b/log4j-slf4j-impl/pom.xml index 6eb6f93585e..0cc3b4d7736 100644 --- a/log4j-slf4j-impl/pom.xml +++ b/log4j-slf4j-impl/pom.xml @@ -27,18 +27,17 @@ jar Apache Log4j SLF4J Binding The Apache Log4j SLF4J API binding to Log4j 2 Core + - 1.7.36 + 1.7.36 - org.slf4j slf4j-api - ${slf4j.version} + ${slf4j1.version} diff --git a/log4j-slf4j2-impl/pom.xml b/log4j-slf4j2-impl/pom.xml index 4bb39542067..279ee47b15e 100644 --- a/log4j-slf4j2-impl/pom.xml +++ b/log4j-slf4j2-impl/pom.xml @@ -29,6 +29,20 @@ Apache Log4j SLF4J 2.0 Binding The Apache Log4j SLF4J 2.0 API binding to Log4j 2 Core + + 2.0.9 + + + + + + org.slf4j + slf4j-api + ${slf4j2.version} + + + + org.osgi diff --git a/log4j-to-slf4j/pom.xml b/log4j-to-slf4j/pom.xml index d5d1c4e1727..6b3840e24d3 100644 --- a/log4j-to-slf4j/pom.xml +++ b/log4j-to-slf4j/pom.xml @@ -37,7 +37,20 @@ org.slf4j.*;version="${slf4j.support.range}" + + 2.0.9 + + + + + org.slf4j + slf4j-api + ${slf4j2.version} + + + + org.osgi From 8c84a97c0f9cb08bc855989737d611b36aeb3ecc Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sat, 30 Mar 2024 23:19:17 +0100 Subject: [PATCH 02/10] Do not upgrade to Log4j API 3.x --- .github/dependabot.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index d72ce612e9e..ee90d02cb24 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -158,7 +158,10 @@ updates: update-types: ["version-update:semver-major"] # Plexus Utils 4.x are for Maven 4.x - dependency-name: "org.codehaus.plexus:plexus-utils" - versions: ["4,)"] + versions: ["[4,)"] + # Don't upgrade to 3.x + - dependency-name: "org.apache.logging.log4j:log4j-api" + versions: ["[3,)"] - package-ecosystem: github-actions directory: "/" From 5801da58f855906c5f7c5ad2a83d6fc079f31482 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sat, 30 Mar 2024 23:31:55 +0100 Subject: [PATCH 03/10] Add SLF4J to comparative tests --- log4j-core-its/pom.xml | 14 ++++++++++++++ log4j-perf-test/pom.xml | 1 + 2 files changed, 15 insertions(+) diff --git a/log4j-core-its/pom.xml b/log4j-core-its/pom.xml index 3163e3248e9..00ca85f43f5 100644 --- a/log4j-core-its/pom.xml +++ b/log4j-core-its/pom.xml @@ -33,7 +33,21 @@ true true true + + + 2.0.9 + + + + + org.slf4j + slf4j-api + ${slf4j2.version} + + + + org.apache.logging.log4j diff --git a/log4j-perf-test/pom.xml b/log4j-perf-test/pom.xml index 01e1d883970..6b613981b3c 100644 --- a/log4j-perf-test/pom.xml +++ b/log4j-perf-test/pom.xml @@ -42,6 +42,7 @@ [9, ) true + 2.0.9 From d055d450695e000b1b11c36ab096dcbcdcd65da0 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 28 Mar 2024 15:03:58 +0100 Subject: [PATCH 04/10] Deprecate `o.a.l.l.c.a.r.a.Duration` class for removal --- .../rolling/action/IfLastModifiedTest.java | 7 +---- .../appender/rolling/action/Duration.java | 9 ++++++ .../rolling/action/IfLastModified.java | 28 ++++++++++++++----- .../appender/rolling/action/package-info.java | 2 +- .../plugins/convert/TypeConverters.java | 21 ++++++++++++-- .../config/plugins/convert/package-info.java | 2 +- src/changelog/.2.x.x/deprecate_duration.xml | 7 +++++ 7 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 src/changelog/.2.x.x/deprecate_duration.xml diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java index 333af1ebd46..7160fa14f45 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.attribute.FileTime; +import java.time.Duration; import java.util.List; import org.apache.logging.log4j.core.config.Node; import org.apache.logging.log4j.core.config.NullConfiguration; @@ -43,12 +44,6 @@ @SetSystemProperty(key = "log4j2.status.entries", value = "10") class IfLastModifiedTest { - @Test - public void testGetDurationReturnsConstructorValue() { - final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("P7D")); - assertEquals(0, filter.getAge().compareTo(Duration.parse("P7D"))); - } - @Test public void testAcceptsIfFileAgeEqualToDuration() { final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Duration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Duration.java index 597eceea24a..a9c4f9437b0 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Duration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Duration.java @@ -30,7 +30,9 @@ * This implementation does not support fractions or negative values. * * @see #parse(CharSequence) + * @deprecated since 2.24.0 use {@link java.time.Duration} instead. */ +@Deprecated public class Duration implements Serializable, Comparable { private static final long serialVersionUID = -3756810052716342061L; @@ -66,6 +68,13 @@ public class Duration implements Serializable, Comparable { private static final Pattern PATTERN = Pattern.compile( "P?(?:([0-9]+)D)?" + "(T?(?:([0-9]+)H)?(?:([0-9]+)M)?(?:([0-9]+)?S)?)?", Pattern.CASE_INSENSITIVE); + /** + * @since 2.24.0 + */ + public static Duration ofMillis(final long millis) { + return new Duration(millis / 1000L); + } + /** * The number of seconds in the duration. */ diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java index 6b15f5409f2..ede472cbddf 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java @@ -19,6 +19,7 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -50,8 +51,12 @@ private IfLastModified(final Duration age, final PathCondition[] nestedCondition this.nestedConditions = PathCondition.copy(nestedConditions); } - public Duration getAge() { - return age; + /** + * @deprecated since 2.24.0 without a replacement. + */ + @Deprecated + public org.apache.logging.log4j.core.appender.rolling.action.Duration getAge() { + return org.apache.logging.log4j.core.appender.rolling.action.Duration.ofMillis(age.toMillis()); } public List getNestedConditions() { @@ -89,20 +94,29 @@ public void beforeFileTreeWalk() { IfAll.beforeFileTreeWalk(nestedConditions); } + /** + * @deprecated since 2.24.0 use {@link #createAgeCondition(Duration, PathCondition...)} instead. + */ + @Deprecated + public static IfLastModified createAgeCondition( + final org.apache.logging.log4j.core.appender.rolling.action.Duration age, + final PathCondition... pathConditions) { + return createAgeCondition(Duration.ofMillis(age.toMillis()), pathConditions); + } + /** * Create an IfLastModified condition. * * @param age The path age that is accepted by this condition. Must be a valid Duration. - * @param nestedConditions nested conditions to evaluate if this condition accepts a path + * @param pathConditions Nested conditions to evaluate if this condition accepts a path. * @return An IfLastModified condition. + * @since 2.24.0 */ @PluginFactory public static IfLastModified createAgeCondition( - // @formatter:off @PluginAttribute("age") @Required(message = "No age provided for IfLastModified") final Duration age, - @PluginElement("PathConditions") final PathCondition... nestedConditions) { - // @formatter:on - return new IfLastModified(age, nestedConditions); + @PluginElement("pathConditions") final PathCondition... pathConditions) { + return new IfLastModified(age, Objects.requireNonNull(pathConditions)); } @Override diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/package-info.java index 76054597368..4e9d1a1bb9d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/package-info.java @@ -18,7 +18,7 @@ * Support classes for the Rolling File Appender. */ @Export -@Version("2.20.2") +@Version("2.24.0") package org.apache.logging.log4j.core.appender.rolling.action; import org.osgi.annotation.bundle.Export; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java index 987e68e9cc4..396dea94a4e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java @@ -32,11 +32,11 @@ import java.nio.file.Paths; import java.security.Provider; import java.security.Security; +import java.time.Duration; import java.util.UUID; import java.util.regex.Pattern; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.appender.rolling.action.Duration; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.util.CronExpression; import org.apache.logging.log4j.status.StatusLogger; @@ -224,11 +224,26 @@ public Double convert(final String s) { } /** - * Converts a {@link String} into a {@link Duration}. + * Converts a {@link String} into a {@link org.apache.logging.log4j.core.appender.rolling.action.Duration}. * @since 2.5 + * @deprecated since 2.24.0 use {@link JavaDurationConverter} */ @Plugin(name = "Duration", category = CATEGORY) - public static class DurationConverter implements TypeConverter { + @Deprecated + public static class DurationConverter + implements TypeConverter { + @Override + public org.apache.logging.log4j.core.appender.rolling.action.Duration convert(final String s) { + return org.apache.logging.log4j.core.appender.rolling.action.Duration.parse(s); + } + } + + /** + * Converts a {@link String} into a {@link Duration}. + * @since 2.24.0 + */ + @Plugin(name = "JavaDuration", category = CATEGORY) + public static class JavaDurationConverter implements TypeConverter { @Override public Duration convert(final String s) { return Duration.parse(s); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/package-info.java index 59da1e88bc7..a4300945314 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/package-info.java @@ -20,7 +20,7 @@ * attributes in plugin factory methods. */ @Export -@Version("2.20.2") +@Version("2.24.0") package org.apache.logging.log4j.core.config.plugins.convert; import org.osgi.annotation.bundle.Export; diff --git a/src/changelog/.2.x.x/deprecate_duration.xml b/src/changelog/.2.x.x/deprecate_duration.xml new file mode 100644 index 00000000000..f11e9c569ad --- /dev/null +++ b/src/changelog/.2.x.x/deprecate_duration.xml @@ -0,0 +1,7 @@ + + + Deprecate `org.apache.logging.log4j.core.appender.rolling.action.Duration` class for removal. + From 12ee6326e1a68a65cc5566c16822dbcbab2e3ed3 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 28 Mar 2024 16:18:57 +0100 Subject: [PATCH 05/10] Backport builder from 3.x --- .../rolling/action/IfLastModifiedTest.java | 23 +++++-- .../rolling/action/IfLastModified.java | 64 ++++++++++--------- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java index 7160fa14f45..22bf04e43f1 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java @@ -46,7 +46,8 @@ class IfLastModifiedTest { @Test public void testAcceptsIfFileAgeEqualToDuration() { - final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); + final IfLastModified filter = + IfLastModified.newBuilder().setAge(Duration.parse("PT33S")).build(); final DummyFileAttributes attrs = new DummyFileAttributes(); final long age = 33 * 1000; attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); @@ -55,7 +56,8 @@ public void testAcceptsIfFileAgeEqualToDuration() { @Test public void testAcceptsIfFileAgeExceedsDuration() { - final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); + final IfLastModified filter = + IfLastModified.newBuilder().setAge(Duration.parse("PT33S")).build(); final DummyFileAttributes attrs = new DummyFileAttributes(); final long age = 33 * 1000 + 5; attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); @@ -64,7 +66,8 @@ public void testAcceptsIfFileAgeExceedsDuration() { @Test public void testDoesNotAcceptIfFileAgeLessThanDuration() { - final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S")); + final IfLastModified filter = + IfLastModified.newBuilder().setAge(Duration.parse("PT33S")).build(); final DummyFileAttributes attrs = new DummyFileAttributes(); final long age = 33 * 1000 - 5; attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - age); @@ -74,7 +77,10 @@ public void testDoesNotAcceptIfFileAgeLessThanDuration() { @Test public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { final CountingCondition counter = new CountingCondition(true); - final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter); + final IfLastModified filter = IfLastModified.newBuilder() + .setAge(Duration.parse("PT33S")) + .setNestedConditions(counter) + .build(); final DummyFileAttributes attrs = new DummyFileAttributes(); final long oldEnough = 33 * 1000 + 5; attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - oldEnough); @@ -99,8 +105,10 @@ public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { @Test public void testBeforeTreeWalk() { final CountingCondition counter = new CountingCondition(true); - final IfLastModified filter = - IfLastModified.createAgeCondition(Duration.parse("PT33S"), counter, counter, counter); + final IfLastModified filter = IfLastModified.newBuilder() + .setAge(Duration.parse("PT33S")) + .setNestedConditions(counter, counter, counter) + .build(); filter.beforeFileTreeWalk(); assertEquals(3, counter.getBeforeFileTreeWalkCount()); } @@ -108,7 +116,8 @@ public void testBeforeTreeWalk() { @Test public void testCreateAgeConditionCalledProgrammaticallyThrowsNPEWhenAgeIsNotSpecified() { Duration age = null; - assertThrows(NullPointerException.class, () -> IfLastModified.createAgeCondition(age)); + assertThrows( + NullPointerException.class, () -> IfLastModified.newBuilder().setAge(age)); } @ParameterizedTest diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java index ede472cbddf..031789ecf03 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java @@ -27,7 +27,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; @@ -63,12 +63,6 @@ public List getNestedConditions() { return Collections.unmodifiableList(Arrays.asList(nestedConditions)); } - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, - * java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) - */ @Override public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { final FileTime fileTime = attrs.lastModifiedTime(); @@ -84,39 +78,22 @@ public boolean accept(final Path basePath, final Path relativePath, final BasicF return result; } - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() - */ @Override public void beforeFileTreeWalk() { IfAll.beforeFileTreeWalk(nestedConditions); } /** - * @deprecated since 2.24.0 use {@link #createAgeCondition(Duration, PathCondition...)} instead. + * @deprecated since 2.24.0 use {@link #newBuilder()} instead. */ @Deprecated public static IfLastModified createAgeCondition( final org.apache.logging.log4j.core.appender.rolling.action.Duration age, final PathCondition... pathConditions) { - return createAgeCondition(Duration.ofMillis(age.toMillis()), pathConditions); - } - - /** - * Create an IfLastModified condition. - * - * @param age The path age that is accepted by this condition. Must be a valid Duration. - * @param pathConditions Nested conditions to evaluate if this condition accepts a path. - * @return An IfLastModified condition. - * @since 2.24.0 - */ - @PluginFactory - public static IfLastModified createAgeCondition( - @PluginAttribute("age") @Required(message = "No age provided for IfLastModified") final Duration age, - @PluginElement("pathConditions") final PathCondition... pathConditions) { - return new IfLastModified(age, Objects.requireNonNull(pathConditions)); + return newBuilder() + .setAge(Duration.ofMillis(age.toMillis())) + .setNestedConditions(pathConditions) + .build(); } @Override @@ -124,4 +101,33 @@ public String toString() { final String nested = nestedConditions.length == 0 ? "" : " AND " + Arrays.toString(nestedConditions); return "IfLastModified(age=" + age + nested + ")"; } + + @PluginFactory + public static Builder newBuilder() { + return new Builder(); + } + + public static final class Builder implements org.apache.logging.log4j.core.util.Builder { + @PluginBuilderAttribute + @Required(message = "No age provided for IfLastModified") + private Duration age; + + @PluginElement("nestedConditions") + private PathCondition[] nestedConditions; + + public Builder setAge(final Duration age) { + this.age = age; + return this; + } + + public Builder setNestedConditions(final PathCondition... nestedConditions) { + this.nestedConditions = nestedConditions; + return this; + } + + @Override + public IfLastModified build() { + return isValid() ? new IfLastModified(age, nestedConditions) : null; + } + } } From 8660c3e4a3a0f51cbdf5081f13bcb0a7ce78349c Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 28 Mar 2024 16:48:42 +0100 Subject: [PATCH 06/10] Add `@since` tags --- .../core/appender/rolling/action/IfLastModified.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java index 031789ecf03..0905f9374a2 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java @@ -37,6 +37,7 @@ /** * PathCondition that accepts paths that are older than the specified duration. + * @since 2.5 */ @Plugin(name = "IfLastModified", category = Core.CATEGORY_NAME, printObject = true) public final class IfLastModified implements PathCondition { @@ -52,7 +53,7 @@ private IfLastModified(final Duration age, final PathCondition[] nestedCondition } /** - * @deprecated since 2.24.0 without a replacement. + * @deprecated since 2.24.0. In 3.0.0 the signature will change. */ @Deprecated public org.apache.logging.log4j.core.appender.rolling.action.Duration getAge() { @@ -102,11 +103,17 @@ public String toString() { return "IfLastModified(age=" + age + nested + ")"; } + /** + * @since 2.24.0 + */ @PluginFactory public static Builder newBuilder() { return new Builder(); } + /** + * @since 2.24.0 + */ public static final class Builder implements org.apache.logging.log4j.core.util.Builder { @PluginBuilderAttribute @Required(message = "No age provided for IfLastModified") From c2e0dc22b47fe6038e16c4af0d2b636eae992e0e Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 28 Mar 2024 16:59:49 +0100 Subject: [PATCH 07/10] Use deprecated class internally in builder By using the deprecated class internally, we benefit from the more lax parsing rules, withouth exposing the class in the API. --- .../log4j/core/appender/rolling/action/IfLastModified.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java index 0905f9374a2..de53bfaa7a8 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java @@ -117,13 +117,13 @@ public static Builder newBuilder() { public static final class Builder implements org.apache.logging.log4j.core.util.Builder { @PluginBuilderAttribute @Required(message = "No age provided for IfLastModified") - private Duration age; + private org.apache.logging.log4j.core.appender.rolling.action.Duration age; @PluginElement("nestedConditions") private PathCondition[] nestedConditions; public Builder setAge(final Duration age) { - this.age = age; + this.age = org.apache.logging.log4j.core.appender.rolling.action.Duration.ofMillis(age.toMillis()); return this; } From ea83bb7c975f716b539d790c411c7fa19724887d Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 28 Mar 2024 17:26:47 +0100 Subject: [PATCH 08/10] Fix test failures --- .../log4j/core/appender/rolling/action/IfLastModified.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java index de53bfaa7a8..e8a105edf5f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java @@ -28,8 +28,8 @@ import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; import org.apache.logging.log4j.core.util.Clock; import org.apache.logging.log4j.core.util.ClockFactory; @@ -106,7 +106,7 @@ public String toString() { /** * @since 2.24.0 */ - @PluginFactory + @PluginBuilderFactory public static Builder newBuilder() { return new Builder(); } @@ -134,7 +134,7 @@ public Builder setNestedConditions(final PathCondition... nestedConditions) { @Override public IfLastModified build() { - return isValid() ? new IfLastModified(age, nestedConditions) : null; + return isValid() ? new IfLastModified(Duration.ofMillis(age.toMillis()), nestedConditions) : null; } } } From b1c9cd8b62a19e0753e55351c29a74ed4e1b35a6 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 29 Mar 2024 15:32:14 +0100 Subject: [PATCH 09/10] Remove `java.time.Duration` converter --- .../config/plugins/convert/TypeConverters.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java index 396dea94a4e..3e005f07c5d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java @@ -32,7 +32,6 @@ import java.nio.file.Paths; import java.security.Provider; import java.security.Security; -import java.time.Duration; import java.util.UUID; import java.util.regex.Pattern; import org.apache.logging.log4j.Level; @@ -226,7 +225,7 @@ public Double convert(final String s) { /** * Converts a {@link String} into a {@link org.apache.logging.log4j.core.appender.rolling.action.Duration}. * @since 2.5 - * @deprecated since 2.24.0 use {@link JavaDurationConverter} + * @deprecated since 2.24.0. A {@link java.time.Duration} converter will be available in 3.0.0. */ @Plugin(name = "Duration", category = CATEGORY) @Deprecated @@ -238,18 +237,6 @@ public org.apache.logging.log4j.core.appender.rolling.action.Duration convert(fi } } - /** - * Converts a {@link String} into a {@link Duration}. - * @since 2.24.0 - */ - @Plugin(name = "JavaDuration", category = CATEGORY) - public static class JavaDurationConverter implements TypeConverter { - @Override - public Duration convert(final String s) { - return Duration.parse(s); - } - } - /** * Converts a {@link String} into a {@link File}. */ From d0cabc541a83b8747fc714574b5e363768222c79 Mon Sep 17 00:00:00 2001 From: ASF Logging Services RM Date: Sat, 30 Mar 2024 23:05:31 +0000 Subject: [PATCH 10/10] Update `org.mongodb:bson` to version `3.12.14` (#2409) --- log4j-mongodb3/pom.xml | 2 +- src/changelog/.2.x.x/update_org_mongodb_bson.xml | 8 ++++++++ src/site/_release-notes/_2.x.x.adoc | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/changelog/.2.x.x/update_org_mongodb_bson.xml diff --git a/log4j-mongodb3/pom.xml b/log4j-mongodb3/pom.xml index 6efde08146f..b1225582b2a 100644 --- a/log4j-mongodb3/pom.xml +++ b/log4j-mongodb3/pom.xml @@ -43,7 +43,7 @@ org.apache.logging.log4j.core - 3.12.11 + 3.12.14 diff --git a/src/changelog/.2.x.x/update_org_mongodb_bson.xml b/src/changelog/.2.x.x/update_org_mongodb_bson.xml new file mode 100644 index 00000000000..2624e701a36 --- /dev/null +++ b/src/changelog/.2.x.x/update_org_mongodb_bson.xml @@ -0,0 +1,8 @@ + + + + Update `org.mongodb:bson` to version `3.12.14` + diff --git a/src/site/_release-notes/_2.x.x.adoc b/src/site/_release-notes/_2.x.x.adoc index 602c818cbc9..d515798b0e1 100644 --- a/src/site/_release-notes/_2.x.x.adoc +++ b/src/site/_release-notes/_2.x.x.adoc @@ -35,6 +35,7 @@ This releases contains ... * Fix usage of `log4j-api` in GraalVM without additional reachability data. (https://github.com/apache/logging-log4j2/pull/1539[1539]) * Centralize initialization in the `Provider` class and deprecate `log4j2.loggerContextFactory` property. (https://github.com/apache/logging-log4j2/pull/2374[2374]) * Remove `log4j-kubernetes` lookup. User should migrate to https://github.com/fabric8io/kubernetes-client/blob/main/doc/KubernetesLog4j.md[`kubernetes-log4j`] (https://github.com/apache/logging-log4j2/pull/2412[2412]) +* Deprecate `org.apache.logging.log4j.core.appender.rolling.action.Duration` class for removal. [#release-notes-2-x-x-fixed] === Fixed @@ -55,4 +56,5 @@ This releases contains ... * Update `org.apache.activemq:activemq-broker` to version `6.1.0` (https://github.com/apache/logging-log4j2/pull/2387[2387]) * Update `org.apache.commons:commons-compress` to version `1.26.1` (https://github.com/apache/logging-log4j2/pull/2361[2361]) * Update `org.awaitility:awaitility` to version `4.2.1` (https://github.com/apache/logging-log4j2/pull/2386[2386]) +* Update `org.mongodb:bson` to version `3.12.14` (https://github.com/apache/logging-log4j2/pull/2409[2409]) * Update `org.springframework:spring-framework-bom` to version `5.3.33` (https://github.com/apache/logging-log4j2/pull/2378[2378])