Skip to content
5 changes: 4 additions & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "/"
Expand Down
20 changes: 14 additions & 6 deletions log4j-core-its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,21 @@
<maven.install.skip>true</maven.install.skip>
<sign.skip>true</sign.skip>
<spotbugs.skip>true</spotbugs.skip>

<!-- Dependency versions -->
<slf4j2.version>2.0.9</slf4j2.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j2.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down Expand Up @@ -153,12 +167,6 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<!-- SLF4J tests -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
5 changes: 0 additions & 5 deletions log4j-core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@
<artifactId>plexus-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Used for testing HttpAppender -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,15 +44,10 @@
@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"));
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);
Expand All @@ -60,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);
Expand All @@ -69,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);
Expand All @@ -79,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);
Expand All @@ -104,16 +105,19 @@ 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());
}

@Test
public void testCreateAgeConditionCalledProgrammaticallyThrowsNPEWhenAgeIsNotSpecified() {
Duration age = null;
assertThrows(NullPointerException.class, () -> IfLastModified.createAgeCondition(age));
assertThrows(
NullPointerException.class, () -> IfLastModified.newBuilder().setAge(age));
}

@ParameterizedTest
Expand Down
7 changes: 0 additions & 7 deletions log4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,6 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- Kafka needs slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration> {
private static final long serialVersionUID = -3756810052716342061L;

Expand Down Expand Up @@ -66,6 +68,13 @@ public class Duration implements Serializable, Comparable<Duration> {
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@
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;
import java.util.Objects;
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.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;
import org.apache.logging.log4j.status.StatusLogger;

/**
* 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 {
Expand All @@ -50,20 +52,18 @@ private IfLastModified(final Duration age, final PathCondition[] nestedCondition
this.nestedConditions = PathCondition.copy(nestedConditions);
}

public Duration getAge() {
return age;
/**
* @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() {
return org.apache.logging.log4j.core.appender.rolling.action.Duration.ofMillis(age.toMillis());
}

public List<PathCondition> 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();
Expand All @@ -79,35 +79,62 @@ 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);
}

/**
* 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
* @return An IfLastModified condition.
* @deprecated since 2.24.0 use {@link #newBuilder()} instead.
*/
@PluginFactory
@Deprecated
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);
final org.apache.logging.log4j.core.appender.rolling.action.Duration age,
final PathCondition... pathConditions) {
return newBuilder()
.setAge(Duration.ofMillis(age.toMillis()))
.setNestedConditions(pathConditions)
.build();
}

@Override
public String toString() {
final String nested = nestedConditions.length == 0 ? "" : " AND " + Arrays.toString(nestedConditions);
return "IfLastModified(age=" + age + nested + ")";
}

/**
* @since 2.24.0
*/
@PluginBuilderFactory
public static Builder newBuilder() {
return new Builder();
}

/**
* @since 2.24.0
*/
public static final class Builder implements org.apache.logging.log4j.core.util.Builder<IfLastModified> {
@PluginBuilderAttribute
@Required(message = "No age provided for IfLastModified")
private org.apache.logging.log4j.core.appender.rolling.action.Duration age;

@PluginElement("nestedConditions")
private PathCondition[] nestedConditions;

public Builder setAge(final Duration age) {
this.age = org.apache.logging.log4j.core.appender.rolling.action.Duration.ofMillis(age.toMillis());
return this;
}

public Builder setNestedConditions(final PathCondition... nestedConditions) {
this.nestedConditions = nestedConditions;
return this;
}

@Override
public IfLastModified build() {
return isValid() ? new IfLastModified(Duration.ofMillis(age.toMillis()), nestedConditions) : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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;
Expand Down Expand Up @@ -224,14 +223,17 @@ 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. A {@link java.time.Duration} converter will be available in 3.0.0.
*/
@Plugin(name = "Duration", category = CATEGORY)
public static class DurationConverter implements TypeConverter<Duration> {
@Deprecated
public static class DurationConverter
implements TypeConverter<org.apache.logging.log4j.core.appender.rolling.action.Duration> {
@Override
public Duration convert(final String s) {
return Duration.parse(s);
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions log4j-mongodb3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>

<!-- Dependency versions -->
<mongodb3.version>3.12.11</mongodb3.version>
<mongodb3.version>3.12.14</mongodb3.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -161,11 +161,6 @@
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</plugin>

Expand Down
5 changes: 0 additions & 5 deletions log4j-mongodb4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</plugin>

Expand Down
Loading