From d4002a0ba81810873768e9adf65ee865d9361d41 Mon Sep 17 00:00:00 2001 From: Junhyeok Lee Date: Thu, 19 Jun 2025 00:27:00 +0900 Subject: [PATCH] Deprecate withers in 2.x in favor of setters --- .../DailyRollingFileAppenderBuilder.java | 16 +- .../EnhancedRollingFileAppenderBuilder.java | 12 +- .../appender/FileAppenderBuilder.java | 4 +- .../appender/RollingFileAppenderBuilder.java | 16 +- .../builders/layout/PatternLayoutBuilder.java | 4 +- .../builders/layout/SimpleLayoutBuilder.java | 8 +- .../builders/layout/TTCCLayoutBuilder.java | 4 +- .../java/org/apache/log4j/CategoryTest.java | 2 +- .../java/org/apache/log4j/LoggerTest.java | 2 +- .../log4j/layout/Log4j1SyslogLayoutTest.java | 2 +- .../core/appender/ConsoleAppenderTest.java | 2 +- .../appender/FileAppenderBuilderTest.java | 4 +- .../appender/FileAppenderPermissionsTest.java | 30 +-- .../log4j/core/appender/FileAppenderTest.java | 32 +-- .../core/appender/InMemoryAppenderTest.java | 4 +- .../appender/OutputStreamAppenderTest.java | 8 +- .../appender/ReconfigureAppenderTest.java | 18 +- .../rolling/CronTriggeringPolicyTest.java | 16 +- .../OnStartupTriggeringPolicyTest.java | 10 +- ...AppenderDirectWriteWithHtmlLayoutTest.java | 10 +- .../rolling/RollingAppenderSizeTest.java | 8 +- .../RollingFileAppenderAccessTest.java | 6 +- .../RollingFileAppenderLayoutTest.java | 8 +- .../rolling/RollingFileManagerTest.java | 8 +- .../RollingRandomAccessFileManagerTest.java | 10 +- .../core/async/AsyncLoggerConfigTest.java | 12 +- .../core/config/CustomConfigurationTest.java | 20 +- .../core/config/JiraLog4j2_2134Test.java | 8 +- .../log4j/core/config/LoggerConfigTest.java | 38 ++-- ...ternLayoutDefaultExceptionHandlerTest.java | 6 +- .../log4j/core/layout/PatternLayoutTest.java | 130 ++++++------ .../core/layout/PatternSelectorTest.java | 8 +- .../log4j/core/appender/AbstractAppender.java | 4 +- .../core/appender/AbstractFileAppender.java | 81 ++++++++ .../log4j/core/appender/AppenderSet.java | 18 ++ .../log4j/core/appender/FileAppender.java | 97 ++++++++- .../appender/MemoryMappedFileAppender.java | 2 +- .../appender/RandomAccessFileAppender.java | 6 +- .../core/appender/RollingFileAppender.java | 140 +++++++++++-- .../RollingRandomAccessFileAppender.java | 120 +++++++++-- .../core/appender/ScriptAppenderSelector.java | 36 ++++ .../log4j/core/appender/db/ColumnMapping.java | 6 +- .../core/appender/db/jdbc/ColumnConfig.java | 6 +- .../log4j/core/appender/package-info.java | 2 +- .../rolling/DefaultRolloverStrategy.java | 116 +++++++++-- .../rolling/DirectWriteRolloverStrategy.java | 90 +++++++-- .../rolling/TimeBasedTriggeringPolicy.java | 31 ++- .../action/PosixViewAttributeAction.java | 108 +++++++++- .../appender/rolling/action/package-info.java | 2 +- .../core/appender/rolling/package-info.java | 2 +- .../log4j/core/appender/routing/Routes.java | 36 ++++ .../appender/routing/RoutingAppender.java | 35 ++++ .../core/appender/routing/package-info.java | 2 +- .../log4j/core/config/LoggerConfig.java | 189 +++++++++++++++--- .../log4j/core/config/package-info.java | 2 +- .../logging/log4j/core/layout/GelfLayout.java | 12 +- .../log4j/core/layout/PatternLayout.java | 131 ++++++++++-- .../log4j/core/layout/package-info.java | 2 +- .../json/resolver/PatternResolver.java | 8 +- .../perf/jmh/ThreadContextBenchmark2.java | 8 +- ...nstantPatternFormatterImpactBenchmark.java | 6 +- .../log4j/perf/nogc/ClassicLogger.java | 4 +- .../.2.x.x/3750_deprecate_withers.xml | 12 ++ 63 files changed, 1374 insertions(+), 406 deletions(-) create mode 100644 src/changelog/.2.x.x/3750_deprecate_withers.xml diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java index 3e2a58e5a04..4920aaa80ae 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java @@ -180,25 +180,25 @@ private Appender createAppender( } final String filePattern = fileName + "%d{" + datePattern + "}"; final TriggeringPolicy timePolicy = - TimeBasedTriggeringPolicy.newBuilder().withModulate(true).build(); + TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build(); final TriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(timePolicy); final RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder() - .withConfig(configuration) - .withMax(Integer.toString(Integer.MAX_VALUE)) + .setConfig(configuration) + .setMax(Integer.toString(Integer.MAX_VALUE)) .build(); return AppenderWrapper.adapt(RollingFileAppender.newBuilder() .setName(name) .setConfiguration(configuration) .setLayout(fileLayout) .setFilter(fileFilter) - .withFileName(fileName) - .withAppend(append) + .setFileName(fileName) + .setAppend(append) .setBufferedIo(bufferedIo) .setBufferSize(bufferSize) .setImmediateFlush(immediateFlush) - .withFilePattern(filePattern) - .withPolicy(policy) - .withStrategy(strategy) + .setFilePattern(filePattern) + .setPolicy(policy) + .setStrategy(strategy) .build()); } } diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/EnhancedRollingFileAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/EnhancedRollingFileAppenderBuilder.java index d4eb24500ac..26377e7d1be 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/EnhancedRollingFileAppenderBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/EnhancedRollingFileAppenderBuilder.java @@ -259,7 +259,7 @@ private Appender createAppender( final DefaultRolloverStrategy.Builder rolloverStrategyBuilder = DefaultRolloverStrategy.newBuilder(); switch (rollingPolicyClassName) { case FIXED_WINDOW_ROLLING_POLICY: - rolloverStrategyBuilder.withMin(Integer.toString(minIndex)).withMax(Integer.toString(maxIndex)); + rolloverStrategyBuilder.setMin(Integer.toString(minIndex)).setMax(Integer.toString(maxIndex)); break; case TIME_BASED_ROLLING_POLICY: break; @@ -276,18 +276,18 @@ private Appender createAppender( return null; } return AppenderWrapper.adapt(RollingFileAppender.newBuilder() - .withAppend(append) + .setAppend(append) .setBufferedIo(bufferedIo) .setBufferSize(bufferedIo ? bufferSize : 0) .setConfiguration(configuration) - .withFileName(actualFileName) - .withFilePattern(fileNamePattern) + .setFileName(actualFileName) + .setFilePattern(fileNamePattern) .setFilter(fileFilter) .setImmediateFlush(actualImmediateFlush) .setLayout(fileLayout) .setName(name) - .withPolicy(actualTriggeringPolicy) - .withStrategy(rolloverStrategyBuilder.build()) + .setPolicy(actualTriggeringPolicy) + .setStrategy(rolloverStrategyBuilder.build()) .build()); } } diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/FileAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/FileAppenderBuilder.java index afab23d1f70..9d1f29a962e 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/FileAppenderBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/FileAppenderBuilder.java @@ -158,9 +158,9 @@ private Appender createAppender( .setConfiguration(configuration) .setLayout(fileLayout) .setFilter(fileFilter) - .withFileName(fileName) + .setFileName(fileName) .setImmediateFlush(immediateFlush) - .withAppend(append) + .setAppend(append) .setBufferedIo(bufferedIo) .setBufferSize(bufferSize) .build()); diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java index 6692a58f0c1..72243829667 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java @@ -188,23 +188,23 @@ private Appender createAppender( final SizeBasedTriggeringPolicy sizePolicy = SizeBasedTriggeringPolicy.createPolicy(maxSize); final CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy); final RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder() - .withConfig(config) - .withMax(maxBackups) - .withFileIndex("min") + .setConfig(config) + .setMax(maxBackups) + .setFileIndex("min") .build(); return AppenderWrapper.adapt(RollingFileAppender.newBuilder() .setName(name) .setConfiguration(config) .setLayout(fileLayout) .setFilter(fileFilter) - .withAppend(append) + .setAppend(append) .setBufferedIo(bufferedIo) .setBufferSize(bufferSize) .setImmediateFlush(immediateFlush) - .withFileName(fileName) - .withFilePattern(filePattern) - .withPolicy(policy) - .withStrategy(strategy) + .setFileName(fileName) + .setFilePattern(filePattern) + .setPolicy(policy) + .setStrategy(strategy) .build()); } } diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/PatternLayoutBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/PatternLayoutBuilder.java index 2e1aab0eba2..9eaffb4bc0d 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/PatternLayoutBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/PatternLayoutBuilder.java @@ -83,7 +83,7 @@ Layout createLayout(String pattern, final Log4j1Configuration config) { pattern = PatternLayout.DEFAULT_CONVERSION_PATTERN; } return LayoutWrapper.adapt(PatternLayout.newBuilder() - .withPattern(pattern + .setPattern(pattern // Log4j 2 and Log4j 1 level names differ for custom levels .replaceAll("%([-\\.\\d]*)p(?!\\w)", "%$1v1Level") // Log4j 2's %x (NDC) is not compatible with Log4j 1's @@ -99,7 +99,7 @@ Layout createLayout(String pattern, final Log4j1Configuration config) { // Log4j 2: "{foo=bar,hoo=boo}" // Use %properties to get the Log4j 1 format .replaceAll("%([-\\.\\d]*)X(?!\\w)", "%$1properties")) - .withConfiguration(config) + .setConfiguration(config) .build()); } } diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/SimpleLayoutBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/SimpleLayoutBuilder.java index 8c035c3504a..7b16e54d871 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/SimpleLayoutBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/SimpleLayoutBuilder.java @@ -35,16 +35,16 @@ public class SimpleLayoutBuilder implements LayoutBuilder { @Override public Layout parse(final Element layoutElement, final XmlConfiguration config) { return new LayoutWrapper(PatternLayout.newBuilder() - .withPattern("%v1Level - %m%n") - .withConfiguration(config) + .setPattern("%v1Level - %m%n") + .setConfiguration(config) .build()); } @Override public Layout parse(final PropertiesConfiguration config) { return new LayoutWrapper(PatternLayout.newBuilder() - .withPattern("%v1Level - %m%n") - .withConfiguration(config) + .setPattern("%v1Level - %m%n") + .setConfiguration(config) .build()); } } diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/TTCCLayoutBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/TTCCLayoutBuilder.java index 8f5c5b18994..ae07ff39489 100644 --- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/TTCCLayoutBuilder.java +++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/layout/TTCCLayoutBuilder.java @@ -130,8 +130,8 @@ private Layout createLayout( } sb.append("- %m%n"); return LayoutWrapper.adapt(PatternLayout.newBuilder() - .withPattern(sb.toString()) - .withConfiguration(config) + .setPattern(sb.toString()) + .setConfiguration(config) .build()); } } diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java index 1604f82c2af..6dd7305c07e 100644 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java +++ b/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java @@ -239,7 +239,7 @@ void testSetPriorityNull() { void testClassName() { final Category category = Category.getInstance("TestCategory"); final Layout layout = - PatternLayout.newBuilder().withPattern("%d %p %C{1.} [%t] %m%n").build(); + PatternLayout.newBuilder().setPattern("%d %p %C{1.} [%t] %m%n").build(); final ListAppender appender = new ListAppender("List2", null, layout, false, false); appender.start(); category.setAdditivity(false); diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java index da857121038..f1f93599d8b 100644 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java +++ b/log4j-1.2-api/src/test/java/org/apache/log4j/LoggerTest.java @@ -477,7 +477,7 @@ void testIsTraceEnabled() { @SuppressWarnings("deprecation") void testLog() { final PatternLayout layout = - PatternLayout.newBuilder().withPattern("%d %C %L %m").build(); + PatternLayout.newBuilder().setPattern("%d %C %L %m").build(); final ListAppender appender = new ListAppender("List", null, layout, false, false); appender.start(); final Logger root = Logger.getRootLogger(); diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1SyslogLayoutTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1SyslogLayoutTest.java index b19382edd3a..e684c3a5b94 100644 --- a/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1SyslogLayoutTest.java +++ b/log4j-1.2-api/src/test/java/org/apache/log4j/layout/Log4j1SyslogLayoutTest.java @@ -78,7 +78,7 @@ void testSimpleLayout( .build(); assertEquals(expected, appenderLayout.toSerializable(logEvent)); final StringLayout messageLayout = - PatternLayout.newBuilder().withPattern("%m").build(); + PatternLayout.newBuilder().setPattern("%m").build(); appenderLayout = Log4j1SyslogLayout.newBuilder() .setFacility(facility) .setHeader(header) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java index 87b4a5077a9..e5ddab6eafd 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ConsoleAppenderTest.java @@ -92,7 +92,7 @@ private void testConsoleStreamManagerDoesNotClose( try { systemSetter.systemSet(psMock); final Layout layout = - PatternLayout.newBuilder().withAlwaysWriteExceptions(true).build(); + PatternLayout.newBuilder().setAlwaysWriteExceptions(true).build(); final ConsoleAppender app = ConsoleAppender.newBuilder() .setLayout(layout) .setTarget(targetName) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderBuilderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderBuilderTest.java index 718349e1f3c..b4fdfc03478 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderBuilderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderBuilderTest.java @@ -67,7 +67,7 @@ public Level getStatusLevel() { assertNull(appender); assertTrue(counter.getAndSet(0) > 0); appender = FileAppender.newBuilder() - .withFileName("target/FileAppenderBuilderTest.log") + .setFileName("target/FileAppenderBuilderTest.log") .build(); assertNull(appender); assertTrue(counter.getAndSet(0) > 0); @@ -76,7 +76,7 @@ public Level getStatusLevel() { assertTrue(counter.getAndSet(0) > 0); appender = FileAppender.newBuilder() .setName("FILE") - .withFileName("target/FileAppenderBuilderTest.log") + .setFileName("target/FileAppenderBuilderTest.log") .build(); assertNotNull(appender); assertEquals(0, counter.get()); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderPermissionsTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderPermissionsTest.java index 1ebf7cbacf3..6e3118628ff 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderPermissionsTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderPermissionsTest.java @@ -70,19 +70,19 @@ void testFilePermissionsAPI(final String filePermissions, final boolean createOn final File file = new File(DIR, "AppenderTest-" + fileIndex + ".log"); final Path path = file.toPath(); final Layout layout = PatternLayout.newBuilder() - .withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) + .setPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) .build(); // @formatter:off final FileAppender appender = FileAppender.newBuilder() - .withFileName(file.getAbsolutePath()) + .setFileName(file.getAbsolutePath()) .setName("test") - .withImmediateFlush(false) + .setImmediateFlush(false) .setIgnoreExceptions(false) - .withBufferedIo(false) - .withBufferSize(1) + .setBufferedIo(false) + .setBufferSize(1) .setLayout(layout) - .withCreateOnDemand(createOnDemand) - .withFilePermissions(filePermissions) + .setCreateOnDemand(createOnDemand) + .setFilePermissions(filePermissions) .build(); // @formatter:on try { @@ -130,20 +130,20 @@ void testFileUserGroupAPI(final String filePermissions, final int fileIndex) thr assertNotNull(group); final Layout layout = PatternLayout.newBuilder() - .withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) + .setPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) .build(); // @formatter:off final FileAppender appender = FileAppender.newBuilder() - .withFileName(file.getAbsolutePath()) + .setFileName(file.getAbsolutePath()) .setName("test") - .withImmediateFlush(true) + .setImmediateFlush(true) .setIgnoreExceptions(false) - .withBufferedIo(false) - .withBufferSize(1) + .setBufferedIo(false) + .setBufferSize(1) .setLayout(layout) - .withFilePermissions(filePermissions) - .withFileOwner(user) - .withFileGroup(group) + .setFilePermissions(filePermissions) + .setFileOwner(user) + .setFileGroup(group) .build(); // @formatter:on try { diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java index 07221c2c811..2867c9a758a 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java @@ -77,14 +77,14 @@ void testLazyCreate(final boolean createOnDemand) { final Layout layout = createPatternLayout(); // @formatter:off final FileAppender appender = FileAppender.newBuilder() - .withFileName(FILE_NAME) + .setFileName(FILE_NAME) .setName("test") - .withImmediateFlush(false) + .setImmediateFlush(false) .setIgnoreExceptions(false) - .withBufferedIo(false) - .withBufferSize(1) + .setBufferedIo(false) + .setBufferSize(1) .setLayout(layout) - .withCreateOnDemand(createOnDemand) + .setCreateOnDemand(createOnDemand) .build(); // @formatter:on assertEquals(createOnDemand, appender.getManager().isCreateOnDemand()); @@ -100,7 +100,7 @@ void testLazyCreate(final boolean createOnDemand) { private static PatternLayout createPatternLayout() { return PatternLayout.newBuilder() - .withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) + .setPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) .build(); } @@ -110,14 +110,14 @@ void testSmallestBufferSize(final boolean createOnDemand) throws Exception { final Layout layout = createPatternLayout(); // @formatter:off final FileAppender appender = FileAppender.newBuilder() - .withFileName(FILE_NAME) + .setFileName(FILE_NAME) .setName("test") - .withImmediateFlush(false) + .setImmediateFlush(false) .setIgnoreExceptions(false) - .withBufferedIo(false) - .withBufferSize(1) + .setBufferedIo(false) + .setBufferSize(1) .setLayout(layout) - .withCreateOnDemand(createOnDemand) + .setCreateOnDemand(createOnDemand) .build(); // @formatter:on try { @@ -243,14 +243,14 @@ private static void writer( final Layout layout = createPatternLayout(); // @formatter:off final FileAppender appender = FileAppender.newBuilder() - .withFileName(FILE_NAME) + .setFileName(FILE_NAME) .setName("test") - .withImmediateFlush(false) + .setImmediateFlush(false) .setIgnoreExceptions(false) - .withLocking(locking) - .withBufferedIo(false) + .setLocking(locking) + .setBufferedIo(false) .setLayout(layout) - .withCreateOnDemand(createOnDemand) + .setCreateOnDemand(createOnDemand) .build(); // @formatter:on assertEquals(createOnDemand, appender.getManager().isCreateOnDemand()); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppenderTest.java index 4bc0c53b765..cad32c266fe 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppenderTest.java @@ -45,7 +45,7 @@ void testAppender() { @Test void testHeaderRequested() { final PatternLayout layout = - PatternLayout.newBuilder().withHeader("HEADERHEADER").build(); + PatternLayout.newBuilder().setHeader("HEADERHEADER").build(); final boolean writeHeader = true; final InMemoryAppender app = new InMemoryAppender("test", layout, null, false, writeHeader); final String expectedHeader = "HEADERHEADER"; @@ -55,7 +55,7 @@ void testHeaderRequested() { @Test void testHeaderSuppressed() { final PatternLayout layout = - PatternLayout.newBuilder().withHeader("HEADERHEADER").build(); + PatternLayout.newBuilder().setHeader("HEADERHEADER").build(); final boolean writeHeader = false; final InMemoryAppender app = new InMemoryAppender("test", layout, null, false, writeHeader); final String expectedHeader = null; diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java index ed09bc11d86..e54d97d6520 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java @@ -108,12 +108,12 @@ void testUpdatePatternWithFileAppender() { final Configuration config = ctx.getConfiguration(); // @formatter:off final Appender appender = FileAppender.newBuilder() - .withFileName("target/" + getClass().getName() + ".log") - .withAppend(false) + .setFileName("target/" + getClass().getName() + ".log") + .setAppend(false) .setName("File") .setIgnoreExceptions(false) - .withBufferedIo(false) - .withBufferSize(4000) + .setBufferedIo(false) + .setBufferSize(4000) .setConfiguration(config) .build(); // @formatter:on diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java index 688ac302044..261c2a2f324 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java @@ -142,19 +142,19 @@ private void createAndAddAppender() { final Logger logger = (Logger) LogManager.getLogger(this.getClass()); final Builder pattern_builder = - PatternLayout.newBuilder().withPattern("[%d{dd-MM-yy HH:mm:ss}] %p %m %throwable %n"); + PatternLayout.newBuilder().setPattern("[%d{dd-MM-yy HH:mm:ss}] %p %m %throwable %n"); final PatternLayout pattern_layout = (PatternLayout) pattern_builder.build(); appender = RollingFileAppender.newBuilder() - .withLayout(pattern_layout) - .withName("rollingfileappender") - .withFilePattern("target/filepattern.%i.log") - .withPolicy(SizeBasedTriggeringPolicy.createPolicy("5 MB")) - .withAppend(true) - .withStrategy(DirectWriteRolloverStrategy.newBuilder() - .withConfig(logger_context.getConfiguration()) - .withMaxFiles("5") + .setLayout(pattern_layout) + .setName("rollingfileappender") + .setFilePattern("target/filepattern.%i.log") + .setPolicy(SizeBasedTriggeringPolicy.createPolicy("5 MB")) + .setAppend(true) + .setStrategy(DirectWriteRolloverStrategy.newBuilder() + .setConfig(logger_context.getConfiguration()) + .setMaxFiles("5") .build()) .setConfiguration(logger_context.getConfiguration()) .build(); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java index 1b6fc7edd80..65f3ccb910f 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/CronTriggeringPolicyTest.java @@ -53,10 +53,10 @@ private void testBuilder() { // @formatter:off final RollingFileAppender raf = RollingFileAppender.newBuilder() .setName("test1") - .withFileName("target/testcmd1.log") - .withFilePattern("target/testcmd1.log.%d{yyyy-MM-dd}") - .withPolicy(createPolicy()) - .withStrategy(createStrategy()) + .setFileName("target/testcmd1.log") + .setFilePattern("target/testcmd1.log.%d{yyyy-MM-dd}") + .setPolicy(createPolicy()) + .setStrategy(createStrategy()) .setConfiguration(configuration) .build(); // @formatter:on @@ -89,10 +89,10 @@ void testRollingRandomAccessFileAppender() { // @formatter:off RollingRandomAccessFileAppender.newBuilder() .setName("test2") - .withFileName("target/testcmd2.log") - .withFilePattern("target/testcmd2.log.%d{yyyy-MM-dd}") - .withPolicy(createPolicy()) - .withStrategy(createStrategy()) + .setFileName("target/testcmd2.log") + .setFilePattern("target/testcmd2.log.%d{yyyy-MM-dd}") + .setPolicy(createPolicy()) + .setStrategy(createStrategy()) .setConfiguration(configuration) .build(); // @formatter:on diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java index 74820472375..548cc1e5076 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java @@ -83,13 +83,13 @@ void testPolicy() throws Exception { assumeTrue(creationTime.equals(fileTime) || creationTime.toMillis() == 0L); final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%msg") - .withConfiguration(configuration) + .setPattern("%msg") + .setConfiguration(configuration) .build(); final RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder() - .withCompressionLevelStr("0") - .withStopCustomActionsOnError(true) - .withConfig(configuration) + .setCompressionLevelStr("0") + .setStopCustomActionsOnError(true) + .setConfig(configuration) .build(); final OnStartupTriggeringPolicy policy = OnStartupTriggeringPolicy.createPolicy(1); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithHtmlLayoutTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithHtmlLayoutTest.java index 887bee97e59..82d3c118eef 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithHtmlLayoutTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWriteWithHtmlLayoutTest.java @@ -70,13 +70,13 @@ private void checkAppenderWithHtmlLayout(final boolean append) throws Interrupte final Configuration config = loggerContextRule.getConfiguration(); final RollingFileAppender appender = RollingFileAppender.newBuilder() .setName("RollingHtml") - .withFilePattern(DIR + "/" + prefix + "_-%d{MM-dd-yy-HH-mm}-%i.html") - .withPolicy(new SizeBasedTriggeringPolicy(500)) - .withStrategy(DirectWriteRolloverStrategy.newBuilder() - .withConfig(config) + .setFilePattern(DIR + "/" + prefix + "_-%d{MM-dd-yy-HH-mm}-%i.html") + .setPolicy(new SizeBasedTriggeringPolicy(500)) + .setStrategy(DirectWriteRolloverStrategy.newBuilder() + .setConfig(config) .build()) .setLayout(HtmlLayout.createDefaultLayout()) - .withAppend(append) + .setAppend(append) .build(); boolean stopped = false; try { diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java index dc245af3058..ea1dbc6e988 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java @@ -72,11 +72,11 @@ private static RollingFileAppender createRollingFileAppender( folder.resolve("rollingtest-%i.log." + fileExtension).toString(); final RollingFileAppender appender = RollingFileAppender.newBuilder() .setName("RollingFile") - .withFileName(fileName) - .withFilePattern(filePattern) + .setFileName(fileName) + .setFilePattern(filePattern) .setLayout(PatternLayout.createDefaultLayout()) - .withPolicy(SizeBasedTriggeringPolicy.createPolicy("500")) - .withCreateOnDemand(createOnDemand) + .setPolicy(SizeBasedTriggeringPolicy.createPolicy("500")) + .setCreateOnDemand(createOnDemand) .build(); appender.start(); return appender; diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java index 44a88a7c45f..d2585fdf596 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java @@ -40,10 +40,10 @@ void testAccessManagerWithBuilder() throws IOException { file.deleteOnExit(); // @formatter:off final RollingFileAppender appender = RollingFileAppender.newBuilder() - .withFileName(file.getCanonicalPath()) - .withFilePattern("FilePattern") + .setFileName(file.getCanonicalPath()) + .setFilePattern("FilePattern") .setName("Name") - .withPolicy(OnStartupTriggeringPolicy.createPolicy(1)) + .setPolicy(OnStartupTriggeringPolicy.createPolicy(1)) .setConfiguration(config) .build(); // @formatter:on diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderLayoutTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderLayoutTest.java index 7ac285ee90d..6fa5e23f4ae 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderLayoutTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderLayoutTest.java @@ -30,10 +30,10 @@ void testDefaultLayout() { assertNotNull(RollingFileAppender.newBuilder() .setName(RollingFileAppenderLayoutTest.class.getName()) .setConfiguration(new DefaultConfiguration()) - .withFileName("log.txt") - .withFilePattern("FilePattern") - .withPolicy(OnStartupTriggeringPolicy.createPolicy(1)) - .withCreateOnDemand(true) // no need to clutter up test folder with another file + .setFileName("log.txt") + .setFilePattern("FilePattern") + .setPolicy(OnStartupTriggeringPolicy.createPolicy(1)) + .setCreateOnDemand(true) // no need to clutter up test folder with another file .build() .getLayout()); // @formatter:on diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManagerTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManagerTest.java index dfa94c3ffe7..78784cfa755 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManagerTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManagerTest.java @@ -82,11 +82,11 @@ public RolloverDescription rollover(final RollingFileManager manager) throws Sec file.deleteOnExit(); final RollingFileAppender appender = RollingFileAppender.newBuilder() - .withFilePattern("FilePattern") + .setFilePattern("FilePattern") .setName("RollingFileAppender") .setConfiguration(config) - .withStrategy(new CustomDirectFileRolloverStrategy(file, config.getConfigurationStrSubstitutor())) - .withPolicy(new SizeBasedTriggeringPolicy(100)) + .setStrategy(new CustomDirectFileRolloverStrategy(file, config.getConfigurationStrSubstitutor())) + .setPolicy(new SizeBasedTriggeringPolicy(100)) .build(); assertNotNull(appender); @@ -167,7 +167,7 @@ void testCreateParentDir() { false, NoOpTriggeringPolicy.INSTANCE, DirectWriteRolloverStrategy.newBuilder() - .withConfig(configuration) + .setConfig(configuration) .build(), null, PatternLayout.createDefaultLayout(configuration), diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java index e3aba8f2583..5937242be68 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java @@ -300,11 +300,11 @@ void testRolloverRetainsFileAttributes() throws Exception { // Create the manager. final RolloverStrategy rolloverStrategy = DefaultRolloverStrategy.newBuilder() - .withMax("7") - .withMin("1") - .withFileIndex("max") - .withStopCustomActionsOnError(false) - .withConfig(new DefaultConfiguration()) + .setMax("7") + .setMin("1") + .setFileIndex("max") + .setStopCustomActionsOnError(false) + .setConfig(new DefaultConfiguration()) .build(); final RollingRandomAccessFileManager manager = RollingRandomAccessFileManager.getRollingRandomAccessFileManager( file.getAbsolutePath(), diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java index 71cba0ffc8f..ab493c57dd6 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java @@ -82,12 +82,12 @@ void testAdditivity(final LoggerContext context) throws Exception { void testIncludeLocationDefaultsToFalse() { final Configuration configuration = new NullConfiguration(); final LoggerConfig rootLoggerConfig = - RootLogger.newAsyncRootBuilder().withConfig(configuration).build(); + RootLogger.newAsyncRootBuilder().setConfig(configuration).build(); assertFalse(rootLoggerConfig.isIncludeLocation(), "Include location should default to false for async loggers"); final LoggerConfig loggerConfig = AsyncLoggerConfig.newAsyncBuilder() - .withConfig(configuration) - .withLoggerName("com.foo.Bar") + .setConfig(configuration) + .setLoggerName("com.foo.Bar") .build(); assertFalse(loggerConfig.isIncludeLocation(), "Include location should default to false for async loggers"); } @@ -97,9 +97,9 @@ void testSingleFilterInvocation() { final Configuration configuration = new NullConfiguration(); final Filter filter = mock(Filter.class); final LoggerConfig config = AsyncLoggerConfig.newAsyncBuilder() - .withLoggerName(FQCN) - .withConfig(configuration) - .withLevel(Level.INFO) + .setLoggerName(FQCN) + .setConfig(configuration) + .setLevel(Level.INFO) .setFilter(filter) .build(); final Appender appender = mock(Appender.class); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java index eb7ad4c298e..ac92595deff 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java @@ -59,16 +59,16 @@ void testConfig(final LoggerContext ctx) { } } final Layout layout = PatternLayout.newBuilder() - .withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) - .withConfiguration(config) + .setPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) + .setConfiguration(config) .build(); final FileAppender appender = FileAppender.newBuilder() .setBufferedIo(false) .setIgnoreExceptions(false) .setName("File") .setLayout(layout) - .withAppend(false) - .withFileName(logFile.toString()) + .setAppend(false) + .setFileName(logFile.toString()) .build(); appender.start(); config.addAppender(appender); @@ -76,12 +76,12 @@ void testConfig(final LoggerContext ctx) { final AppenderRef[] refs = new AppenderRef[] {ref}; final LoggerConfig loggerConfig = LoggerConfig.newBuilder() - .withConfig(config) - .withAdditivity(false) - .withIncludeLocation("true") - .withLevel(Level.INFO) - .withLoggerName("org.apache.logging.log4j") - .withRefs(refs) + .setConfig(config) + .setAdditivity(false) + .setIncludeLocation("true") + .setLevel(Level.INFO) + .setLoggerName("org.apache.logging.log4j") + .setRefs(refs) .build(); loggerConfig.addAppender(appender, null, null); config.addLogger("org.apache.logging.log4j", loggerConfig); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_2134Test.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_2134Test.java index 7f7948c44e8..65021c7d0ab 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_2134Test.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/JiraLog4j2_2134Test.java @@ -42,16 +42,16 @@ void testRefresh() { final Configuration config = ctx.getConfiguration(); final PatternLayout layout = PatternLayout.newBuilder() // @formatter:off - .withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) - .withConfiguration(config) + .setPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN) + .setConfiguration(config) .build(); final Layout layout1 = layout; // @formatter:on final Appender appender = FileAppender.newBuilder() - .withFileName("target/test.log") + .setFileName("target/test.log") .setLayout(layout1) .setConfiguration(config) - .withBufferSize(4000) + .setBufferSize(4000) .setName("File") .build(); // appender.start(); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java index 2b4b18e33bd..b25ef14a48b 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/LoggerConfigTest.java @@ -48,12 +48,12 @@ class LoggerConfigTest { private static LoggerConfig createForProperties(final Property[] properties) { return LoggerConfig.newBuilder() - .withConfig(new NullConfiguration()) - .withAdditivity(true) - .withLevel(Level.INFO) - .withLoggerName("name") - .withIncludeLocation("false") - .withProperties(properties) + .setConfig(new NullConfiguration()) + .setAdditivity(true) + .setLevel(Level.INFO) + .setLoggerName("name") + .setIncludeLocation("false") + .setProperties(properties) .build(); } @@ -109,15 +109,15 @@ void testPropertiesWithSubstitution() { void testLevel() { final Configuration configuration = new DefaultConfiguration(); final LoggerConfig config1 = LoggerConfig.newBuilder() - .withLoggerName("org.apache.logging.log4j.test") - .withLevel(Level.ERROR) - .withAdditivity(false) - .withConfig(configuration) + .setLoggerName("org.apache.logging.log4j.test") + .setLevel(Level.ERROR) + .setAdditivity(false) + .setConfig(configuration) .build(); final LoggerConfig config2 = LoggerConfig.newBuilder() - .withLoggerName("org.apache.logging.log4j") - .withAdditivity(false) - .withConfig(configuration) + .setLoggerName("org.apache.logging.log4j") + .setAdditivity(false) + .setConfig(configuration) .build(); config1.setParent(config2); assertEquals(Level.ERROR, config1.getLevel(), "Unexpected Level"); @@ -131,9 +131,9 @@ void testSingleFilterInvocation() { final Configuration configuration = new NullConfiguration(); final Filter filter = mock(Filter.class); final LoggerConfig config = LoggerConfig.newBuilder() - .withLoggerName(FQCN) - .withConfig(configuration) - .withLevel(Level.INFO) + .setLoggerName(FQCN) + .setConfig(configuration) + .setLevel(Level.INFO) .setFilter(filter) .build(); final Appender appender = mock(Appender.class); @@ -150,9 +150,9 @@ void testSingleFilterInvocation() { void testLevelAndRefsWithoutAppenderRef() { final Configuration configuration = mock(PropertiesConfiguration.class); final LoggerConfig.Builder builder = LoggerConfig.newBuilder() - .withLoggerName(FQCN) - .withConfig(configuration) - .withLevelAndRefs(Level.INFO.name()); + .setLoggerName(FQCN) + .setConfig(configuration) + .setLevelAndRefs(Level.INFO.name()); final LoggerConfig loggerConfig = builder.build(); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutDefaultExceptionHandlerTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutDefaultExceptionHandlerTest.java index 05df1bdd730..14b3176a386 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutDefaultExceptionHandlerTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutDefaultExceptionHandlerTest.java @@ -65,9 +65,9 @@ void default_exception_handler_should_not_be_provided_if_alwaysWriteExceptions_d private static AbstractStringAssert assertThatPatternEncodes( final String pattern, final boolean alwaysWriteExceptions) { final Layout layout = PatternLayout.newBuilder() - .withConfiguration(CONFIG) - .withPattern(pattern) - .withAlwaysWriteExceptions(alwaysWriteExceptions) + .setConfiguration(CONFIG) + .setPattern(pattern) + .setAlwaysWriteExceptions(alwaysWriteExceptions) .build(); final LogEvent event = Log4jLogEvent.newBuilder().setThrown(EXCEPTION).build(); return assertThat(layout.toSerializable(event)).as("pattern=`%s`", pattern); diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java index ba58e68df40..34d5fb99ff7 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java @@ -115,8 +115,8 @@ private void assertEncode(final String expectedStr, final PatternLayout layout, void testEqualsEmptyMarker() { // replace "[]" with the empty string final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("[%logger]%equals{[%marker]}{[]}{} %msg") - .withConfiguration(ctx.getConfiguration()) + .setPattern("[%logger]%equals{[%marker]}{[]}{} %msg") + .setConfiguration(ctx.getConfiguration()) .build(); // Not empty marker final LogEvent event1 = Log4jLogEvent.newBuilder() // @@ -146,9 +146,9 @@ void testHeaderFooterJavaLookup() { // % does not work here. final String pattern = "%d{UNIX} MyApp%n${java:version}%n${java:runtime}%n${java:vm}%n${java:os}%n${java:hw}"; final PatternLayout layout = PatternLayout.newBuilder() - .withConfiguration(ctx.getConfiguration()) - .withHeader("Header: " + pattern) - .withFooter("Footer: " + pattern) + .setConfiguration(ctx.getConfiguration()) + .setHeader("Header: " + pattern) + .setFooter("Footer: " + pattern) .build(); final byte[] header = layout.getHeader(); assertNotNull(header, "No header"); @@ -178,9 +178,9 @@ void testHeaderFooterJavaLookup() { void testHeaderFooterMainLookup() { MainMapLookup.setMainArguments("value0", "value1", "value2"); final PatternLayout layout = PatternLayout.newBuilder() - .withConfiguration(ctx.getConfiguration()) - .withHeader("${main:0}") - .withFooter("${main:2}") + .setConfiguration(ctx.getConfiguration()) + .setHeader("${main:0}") + .setFooter("${main:2}") .build(); final byte[] header = layout.getHeader(); assertNotNull(header, "No header"); @@ -196,10 +196,10 @@ void testHeaderFooterMainLookup() { @Test void testHeaderFooterThreadContext() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%d{UNIX} %m") - .withConfiguration(ctx.getConfiguration()) - .withHeader("${ctx:header}") - .withFooter("${ctx:footer}") + .setPattern("%d{UNIX} %m") + .setConfiguration(ctx.getConfiguration()) + .setHeader("${ctx:header}") + .setFooter("${ctx:footer}") .build(); ThreadContext.put("header", "Hello world Header"); ThreadContext.put("footer", "Hello world Footer"); @@ -213,8 +213,8 @@ void testHeaderFooterThreadContext() { private void testMdcPattern(final String patternStr, final String expectedStr, final boolean useThreadContext) { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern(patternStr) - .withConfiguration(ctx.getConfiguration()) + .setPattern(patternStr) + .setConfiguration(ctx.getConfiguration()) .build(); if (useThreadContext) { ThreadContext.put("key1", "value1"); @@ -267,8 +267,8 @@ void testPatternSelector() { final PatternSelector selector = MarkerPatternSelector.createSelector( patterns, "%d %-5p [%t]: %m%n", true, true, ctx.getConfiguration()); final PatternLayout layout = PatternLayout.newBuilder() - .withPatternSelector(selector) - .withConfiguration(ctx.getConfiguration()) + .setPatternSelector(selector) + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -296,8 +296,8 @@ void testPatternSelector() { @Test void testRegex() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern(regexPattern) - .withConfiguration(ctx.getConfiguration()) + .setPattern(regexPattern) + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -313,8 +313,8 @@ void testRegex() { void testRegexEmptyMarker() { // replace "[]" with the empty string final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("[%logger]%replace{[%marker]}{\\[\\]}{} %msg") - .withConfiguration(ctx.getConfiguration()) + .setPattern("[%logger]%replace{[%marker]}{\\[\\]}{} %msg") + .setConfiguration(ctx.getConfiguration()) .build(); // Not empty marker final LogEvent event1 = Log4jLogEvent.newBuilder() // @@ -344,8 +344,8 @@ void testRegexEmptyMarker() { void testEqualsMarkerWithMessageSubstitution() { // replace "[]" with the empty string final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("[%logger]%equals{[%marker]}{[]}{[%msg]}") - .withConfiguration(ctx.getConfiguration()) + .setPattern("[%logger]%equals{[%marker]}{[]}{[%msg]}") + .setConfiguration(ctx.getConfiguration()) .build(); // Not empty marker final LogEvent event1 = Log4jLogEvent.newBuilder() // @@ -371,8 +371,8 @@ void testEqualsMarkerWithMessageSubstitution() { @Test void testSpecialChars() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("\\\\%level\\t%msg\\n\\t%logger\\r\\n\\f") - .withConfiguration(ctx.getConfiguration()) + .setPattern("\\\\%level\\t%msg\\n\\t%logger\\r\\n\\f") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -393,8 +393,8 @@ void testSpecialChars() { @Test void testUnixTime() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%d{UNIX} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%d{UNIX} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -419,8 +419,8 @@ void testUnixTime() { @SuppressWarnings("unused") private void testUnixTime(final String pattern) { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern(pattern + " %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern(pattern + " %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -445,8 +445,8 @@ private void testUnixTime(final String pattern) { @Test void testUnixTimeMillis() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%d{UNIX_MILLIS} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%d{UNIX_MILLIS} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -471,8 +471,8 @@ void testUnixTimeMillis() { @Test void testUsePlatformDefaultIfNoCharset() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%m") + .setConfiguration(ctx.getConfiguration()) .build(); assertEquals(Charset.defaultCharset(), layout.getCharset()); } @@ -480,9 +480,9 @@ void testUsePlatformDefaultIfNoCharset() { @Test void testUseSpecifiedCharsetIfExists() { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%m") - .withConfiguration(ctx.getConfiguration()) - .withCharset(StandardCharsets.UTF_8) + .setPattern("%m") + .setConfiguration(ctx.getConfiguration()) + .setCharset(StandardCharsets.UTF_8) .build(); assertEquals(StandardCharsets.UTF_8, layout.getCharset()); } @@ -491,8 +491,8 @@ void testUseSpecifiedCharsetIfExists() { void testLoggerNameTruncationByRetainingPartsFromEnd() { { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%c{1} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%c{1} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -509,8 +509,8 @@ void testLoggerNameTruncationByRetainingPartsFromEnd() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%c{2} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%c{2} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -528,8 +528,8 @@ void testLoggerNameTruncationByRetainingPartsFromEnd() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%c{20} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%c{20} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -546,8 +546,8 @@ void testLoggerNameTruncationByRetainingPartsFromEnd() { void testCallersFqcnTruncationByRetainingPartsFromEnd() { { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%C{1} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%C{1} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -569,8 +569,8 @@ void testCallersFqcnTruncationByRetainingPartsFromEnd() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%C{2} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%C{2} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -593,8 +593,8 @@ void testCallersFqcnTruncationByRetainingPartsFromEnd() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%C{20} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%C{20} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -612,8 +612,8 @@ void testCallersFqcnTruncationByRetainingPartsFromEnd() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%class{1} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%class{1} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -639,8 +639,8 @@ void testCallersFqcnTruncationByRetainingPartsFromEnd() { void testLoggerNameTruncationByDroppingPartsFromFront() { { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%c{-1} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%c{-1} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -656,8 +656,8 @@ void testLoggerNameTruncationByDroppingPartsFromFront() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%c{-3} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%c{-3} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -675,8 +675,8 @@ void testLoggerNameTruncationByDroppingPartsFromFront() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%logger{-3} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%logger{-3} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -694,8 +694,8 @@ void testLoggerNameTruncationByDroppingPartsFromFront() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%c{-20} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%c{-20} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -712,8 +712,8 @@ void testLoggerNameTruncationByDroppingPartsFromFront() { void testCallersFqcnTruncationByDroppingPartsFromFront() { { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%C{-1} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%C{-1} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -734,8 +734,8 @@ void testCallersFqcnTruncationByDroppingPartsFromFront() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%C{-3} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%C{-3} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -758,8 +758,8 @@ void testCallersFqcnTruncationByDroppingPartsFromFront() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%class{-3} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%class{-3} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) @@ -782,8 +782,8 @@ void testCallersFqcnTruncationByDroppingPartsFromFront() { } { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern("%C{-20} %m") - .withConfiguration(ctx.getConfiguration()) + .setPattern("%C{-20} %m") + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() .setLoggerName(this.getClass().getName()) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java index 0bfb157f835..9712819fc34 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/PatternSelectorTest.java @@ -44,8 +44,8 @@ void testMarkerPatternSelector() { final PatternSelector selector = MarkerPatternSelector.createSelector( patterns, "%d %-5p [%t]: %m%n", true, true, ctx.getConfiguration()); final PatternLayout layout = PatternLayout.newBuilder() - .withPatternSelector(selector) - .withConfiguration(ctx.getConfiguration()) + .setPatternSelector(selector) + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) @@ -77,8 +77,8 @@ void testLevelPatternSelector() { final PatternSelector selector = LevelPatternSelector.createSelector(patterns, "%d %-5p [%t]: %m%n", true, true, ctx.getConfiguration()); final PatternLayout layout = PatternLayout.newBuilder() - .withPatternSelector(selector) - .withConfiguration(ctx.getConfiguration()) + .setPatternSelector(selector) + .setConfiguration(ctx.getConfiguration()) .build(); final LogEvent event1 = Log4jLogEvent.newBuilder() // .setLoggerName(this.getClass().getName()) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java index beaf5134a0e..27530b26243 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractAppender.java @@ -83,8 +83,8 @@ public Layout getOrCreateLayout() { public Layout getOrCreateLayout(final Charset charset) { if (layout == null) { return PatternLayout.newBuilder() - .withCharset(charset) - .withConfiguration(configuration) + .setCharset(charset) + .setConfiguration(configuration) .build(); } return layout; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractFileAppender.java index fc959bc9673..69191e253b5 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractFileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractFileAppender.java @@ -104,46 +104,127 @@ public String getFileGroup() { return fileGroup; } + public B setAdvertise(final boolean advertise) { + this.advertise = advertise; + return asBuilder(); + } + + public B setAdvertiseUri(final String advertiseUri) { + this.advertiseUri = advertiseUri; + return asBuilder(); + } + + public B setAppend(final boolean append) { + this.append = append; + return asBuilder(); + } + + public B setFileName(final String fileName) { + this.fileName = fileName; + return asBuilder(); + } + + public B setCreateOnDemand(final boolean createOnDemand) { + this.createOnDemand = createOnDemand; + return asBuilder(); + } + + public B setLocking(final boolean locking) { + this.locking = locking; + return asBuilder(); + } + + public B setFilePermissions(final String filePermissions) { + this.filePermissions = filePermissions; + return asBuilder(); + } + + public B setFileOwner(final String fileOwner) { + this.fileOwner = fileOwner; + return asBuilder(); + } + + public B setFileGroup(final String fileGroup) { + this.fileGroup = fileGroup; + return asBuilder(); + } + + /** + * @deprecated use {@link #setAdvertise(boolean)}. + */ + @Deprecated public B withAdvertise(final boolean advertise) { this.advertise = advertise; return asBuilder(); } + /** + * @deprecated use {@link #setAdvertiseUri(String)}. + */ + @Deprecated public B withAdvertiseUri(final String advertiseUri) { this.advertiseUri = advertiseUri; return asBuilder(); } + /** + * @deprecated use {@link #setAppend(boolean)}. + */ + @Deprecated public B withAppend(final boolean append) { this.append = append; return asBuilder(); } + /** + * @deprecated use {@link #setFileName(String)}. + */ + @Deprecated public B withFileName(final String fileName) { this.fileName = fileName; return asBuilder(); } + /** + * @deprecated use {@link #setCreateOnDemand(boolean)}. + */ + @Deprecated public B withCreateOnDemand(final boolean createOnDemand) { this.createOnDemand = createOnDemand; return asBuilder(); } + /** + * @deprecated use {@link #setLocking(boolean)}. + */ + @Deprecated public B withLocking(final boolean locking) { this.locking = locking; return asBuilder(); } + /** + * @deprecated use {@link #setFilePermissions(String)}. + */ + @Deprecated public B withFilePermissions(final String filePermissions) { this.filePermissions = filePermissions; return asBuilder(); } + /** + * @deprecated use {@link #setFileOwner(String)}. + */ + @Deprecated public B withFileOwner(final String fileOwner) { this.fileOwner = fileOwner; return asBuilder(); } + /** + * @deprecated use {@link #setFileGroup(String)}. + */ + @Deprecated public B withFileGroup(final String fileGroup) { this.fileGroup = fileGroup; return asBuilder(); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java index 9a4a3aae0d3..911ed56c1cc 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java @@ -81,11 +81,29 @@ public Configuration getConfiguration() { return configuration; } + public Builder setNode(@SuppressWarnings("hiding") final Node node) { + this.node = node; + return this; + } + + public Builder setConfiguration(@SuppressWarnings("hiding") final Configuration configuration) { + this.configuration = configuration; + return this; + } + + /** + * @deprecated use {@link #setNode(Node)}. + */ + @Deprecated public Builder withNode(@SuppressWarnings("hiding") final Node node) { this.node = node; return this; } + /** + * @deprecated use {@link #setConfiguration(Configuration)}. + */ + @Deprecated public Builder withConfiguration(@SuppressWarnings("hiding") final Configuration configuration) { this.configuration = configuration; return this; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java index b284a669d08..664ddadfe04 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java @@ -164,46 +164,127 @@ public String getFileGroup() { return fileGroup; } + public B setAdvertise(final boolean advertise) { + this.advertise = advertise; + return asBuilder(); + } + + public B setAdvertiseUri(final String advertiseUri) { + this.advertiseUri = advertiseUri; + return asBuilder(); + } + + public B setAppend(final boolean append) { + this.append = append; + return asBuilder(); + } + + public B setFileName(final String fileName) { + this.fileName = fileName; + return asBuilder(); + } + + public B setCreateOnDemand(final boolean createOnDemand) { + this.createOnDemand = createOnDemand; + return asBuilder(); + } + + public B setLocking(final boolean locking) { + this.locking = locking; + return asBuilder(); + } + + public B setFilePermissions(final String filePermissions) { + this.filePermissions = filePermissions; + return asBuilder(); + } + + public B setFileOwner(final String fileOwner) { + this.fileOwner = fileOwner; + return asBuilder(); + } + + public B setFileGroup(final String fileGroup) { + this.fileGroup = fileGroup; + return asBuilder(); + } + + /** + * @deprecated use {@link #setAdvertise(boolean)}. + */ + @Deprecated public B withAdvertise(final boolean advertise) { this.advertise = advertise; return asBuilder(); } + /** + * @deprecated use {@link #setAdvertiseUri(String)}. + */ + @Deprecated public B withAdvertiseUri(final String advertiseUri) { this.advertiseUri = advertiseUri; return asBuilder(); } + /** + * @deprecated use {@link #setAppend(boolean)}. + */ + @Deprecated public B withAppend(final boolean append) { this.append = append; return asBuilder(); } + /** + * @deprecated use {@link #setFileName(String)}. + */ + @Deprecated public B withFileName(final String fileName) { this.fileName = fileName; return asBuilder(); } + /** + * @deprecated use {@link #setCreateOnDemand(boolean)}. + */ + @Deprecated public B withCreateOnDemand(final boolean createOnDemand) { this.createOnDemand = createOnDemand; return asBuilder(); } + /** + * @deprecated use {@link #setLocking(boolean)}. + */ + @Deprecated public B withLocking(final boolean locking) { this.locking = locking; return asBuilder(); } + /** + * @deprecated use {@link #setFilePermissions(String)}. + */ + @Deprecated public B withFilePermissions(final String filePermissions) { this.filePermissions = filePermissions; return asBuilder(); } + /** + * @deprecated use {@link #setFileOwner(String)}. + */ + @Deprecated public B withFileOwner(final String fileOwner) { this.fileOwner = fileOwner; return asBuilder(); } + /** + * @deprecated use {@link #setFileGroup(String)}. + */ + @Deprecated public B withFileGroup(final String fileGroup) { this.fileGroup = fileGroup; return asBuilder(); @@ -251,18 +332,18 @@ public static > FileAppender createAppender( final String advertiseUri, final Configuration config) { return FileAppender.newBuilder() - .withAdvertise(Boolean.parseBoolean(advertise)) - .withAdvertiseUri(advertiseUri) - .withAppend(Booleans.parseBoolean(append, true)) - .withBufferedIo(Booleans.parseBoolean(bufferedIo, true)) - .withBufferSize(Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE)) + .setAdvertise(Boolean.parseBoolean(advertise)) + .setAdvertiseUri(advertiseUri) + .setAppend(Booleans.parseBoolean(append, true)) + .setBufferedIo(Booleans.parseBoolean(bufferedIo, true)) + .setBufferSize(Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE)) .setConfiguration(config) - .withFileName(fileName) + .setFileName(fileName) .setFilter(filter) .setIgnoreExceptions(Booleans.parseBoolean(ignoreExceptions, true)) - .withImmediateFlush(Booleans.parseBoolean(immediateFlush, true)) + .setImmediateFlush(Booleans.parseBoolean(immediateFlush, true)) .setLayout(layout) - .withLocking(Boolean.parseBoolean(locking)) + .setLocking(Boolean.parseBoolean(locking)) .setName(name) .build(); // @formatter:on diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java index 3721cdab6af..8774263619e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java @@ -239,7 +239,7 @@ public static > MemoryMappedFileAppender createAppender( .setFileName(fileName) .setFilter(filter) .setIgnoreExceptions(ignoreExceptions) - .withImmediateFlush(isImmediateFlush) + .setImmediateFlush(isImmediateFlush) .setLayout(layout) .setName(name) .setRegionLength(regionLength) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java index ef2dd943192..ae7f8776f04 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java @@ -65,7 +65,7 @@ public static class Builder> extends AbstractOutputStreamAp private String advertiseURI; public Builder() { - this.withBufferSize(RandomAccessFileManager.DEFAULT_BUFFER_SIZE); + this.setBufferSize(RandomAccessFileManager.DEFAULT_BUFFER_SIZE); } @Override @@ -225,12 +225,12 @@ public static > RandomAccessFileAppender createAppender( .setAdvertise(isAdvertise) .setAdvertiseURI(advertiseURI) .setAppend(isAppend) - .withBufferSize(bufferSize) + .setBufferSize(bufferSize) .setConfiguration(configuration) .setFileName(fileName) .setFilter(filter) .setIgnoreExceptions(ignoreExceptions) - .withImmediateFlush(isFlush) + .setImmediateFlush(isFlush) .setLayout(layout) .setName(name) .build(); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java index 4995a048914..9fb1c13b326 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java @@ -123,13 +123,13 @@ public RollingFileAppender build() { if (strategy == null) { if (fileName != null) { strategy = DefaultRolloverStrategy.newBuilder() - .withCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) - .withConfig(getConfiguration()) + .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) + .setConfig(getConfiguration()) .build(); } else { strategy = DirectWriteRolloverStrategy.newBuilder() - .withCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) - .withConfig(getConfiguration()) + .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) + .setConfig(getConfiguration()) .build(); } } else if (fileName == null && !(strategy instanceof DirectFileRolloverStrategy)) { @@ -212,31 +212,85 @@ public String getFileGroup() { return fileGroup; } + public B setAdvertise(final boolean advertise) { + this.advertise = advertise; + return asBuilder(); + } + + public B setAdvertiseUri(final String advertiseUri) { + this.advertiseUri = advertiseUri; + return asBuilder(); + } + + public B setAppend(final boolean append) { + this.append = append; + return asBuilder(); + } + + public B setFileName(final String fileName) { + this.fileName = fileName; + return asBuilder(); + } + + public B setCreateOnDemand(final boolean createOnDemand) { + this.createOnDemand = createOnDemand; + return asBuilder(); + } + + public B setLocking(final boolean locking) { + this.locking = locking; + return asBuilder(); + } + + /** + * @deprecated use {@link #setAdvertise(boolean)}. + */ + @Deprecated public B withAdvertise(final boolean advertise) { this.advertise = advertise; return asBuilder(); } + /** + * @deprecated use {@link #setAdvertiseUri(String)}. + */ + @Deprecated public B withAdvertiseUri(final String advertiseUri) { this.advertiseUri = advertiseUri; return asBuilder(); } + /** + * @deprecated use {@link #setAppend(boolean)}. + */ + @Deprecated public B withAppend(final boolean append) { this.append = append; return asBuilder(); } + /** + * @deprecated use {@link #setFileName(String)}. + */ + @Deprecated public B withFileName(final String fileName) { this.fileName = fileName; return asBuilder(); } + /** + * @deprecated use {@link #setCreateOnDemand(boolean)}. + */ + @Deprecated public B withCreateOnDemand(final boolean createOnDemand) { this.createOnDemand = createOnDemand; return asBuilder(); } + /** + * @deprecated use {@link #setLocking(boolean)}. + */ + @Deprecated public B withLocking(final boolean locking) { this.locking = locking; return asBuilder(); @@ -254,31 +308,85 @@ public RolloverStrategy getStrategy() { return strategy; } + public B setFilePattern(final String filePattern) { + this.filePattern = filePattern; + return asBuilder(); + } + + public B setPolicy(final TriggeringPolicy policy) { + this.policy = policy; + return asBuilder(); + } + + public B setStrategy(final RolloverStrategy strategy) { + this.strategy = strategy; + return asBuilder(); + } + + public B setFilePermissions(final String filePermissions) { + this.filePermissions = filePermissions; + return asBuilder(); + } + + public B setFileOwner(final String fileOwner) { + this.fileOwner = fileOwner; + return asBuilder(); + } + + public B setFileGroup(final String fileGroup) { + this.fileGroup = fileGroup; + return asBuilder(); + } + + /** + * @deprecated use {@link #setFilePattern(String)}. + */ + @Deprecated public B withFilePattern(final String filePattern) { this.filePattern = filePattern; return asBuilder(); } + /** + * @deprecated use {@link #setPolicy(TriggeringPolicy)}. + */ + @Deprecated public B withPolicy(final TriggeringPolicy policy) { this.policy = policy; return asBuilder(); } + /** + * @deprecated use {@link #setStrategy(RolloverStrategy)}. + */ + @Deprecated public B withStrategy(final RolloverStrategy strategy) { this.strategy = strategy; return asBuilder(); } + /** + * @deprecated use {@link #setFilePermissions(String)}. + */ + @Deprecated public B withFilePermissions(final String filePermissions) { this.filePermissions = filePermissions; return asBuilder(); } + /** + * @deprecated use {@link #setFileOwner(String)}. + */ + @Deprecated public B withFileOwner(final String fileOwner) { this.fileOwner = fileOwner; return asBuilder(); } + /** + * @deprecated use {@link #setFileGroup(String)}. + */ + @Deprecated public B withFileGroup(final String fileGroup) { this.fileGroup = fileGroup; return asBuilder(); @@ -406,23 +514,23 @@ public static > RollingFileAppender createAppender( final int bufferSize = Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE); // @formatter:off return RollingFileAppender.newBuilder() - .withAdvertise(Boolean.parseBoolean(advertise)) - .withAdvertiseUri(advertiseUri) - .withAppend(Booleans.parseBoolean(append, true)) - .withBufferedIo(Booleans.parseBoolean(bufferedIO, true)) - .withBufferSize(bufferSize) + .setAdvertise(Boolean.parseBoolean(advertise)) + .setAdvertiseUri(advertiseUri) + .setAppend(Booleans.parseBoolean(append, true)) + .setBufferedIo(Booleans.parseBoolean(bufferedIO, true)) + .setBufferSize(bufferSize) .setConfiguration(config) - .withFileName(fileName) - .withFilePattern(filePattern) + .setFileName(fileName) + .setFilePattern(filePattern) .setFilter(filter) .setIgnoreExceptions(Booleans.parseBoolean(ignore, true)) - .withImmediateFlush(Booleans.parseBoolean(immediateFlush, true)) + .setImmediateFlush(Booleans.parseBoolean(immediateFlush, true)) .setLayout(layout) - .withCreateOnDemand(false) - .withLocking(false) + .setCreateOnDemand(false) + .setLocking(false) .setName(name) - .withPolicy(policy) - .withStrategy(strategy) + .setPolicy(policy) + .setStrategy(strategy) .build(); // @formatter:on } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java index 0668d47aee7..e0e3e513238 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java @@ -58,9 +58,9 @@ public static class Builder> extends AbstractOutputStreamAp implements org.apache.logging.log4j.core.util.Builder { public Builder() { - withBufferSize(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE); + setBufferSize(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE); setIgnoreExceptions(true); - withImmediateFlush(true); + setImmediateFlush(true); } @PluginBuilderAttribute("fileName") @@ -104,13 +104,13 @@ public RollingRandomAccessFileAppender build() { if (strategy == null) { if (fileName != null) { strategy = DefaultRolloverStrategy.newBuilder() - .withCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) - .withConfig(getConfiguration()) + .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) + .setConfig(getConfiguration()) .build(); } else { strategy = DirectWriteRolloverStrategy.newBuilder() - .withCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) - .withConfig(getConfiguration()) + .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION)) + .setConfig(getConfiguration()) .build(); } } else if (fileName == null && !(strategy instanceof DirectFileRolloverStrategy)) { @@ -168,51 +168,141 @@ public RollingRandomAccessFileAppender build() { getPropertyArray()); } + public B setFileName(final String fileName) { + this.fileName = fileName; + return asBuilder(); + } + + public B setFilePattern(final String filePattern) { + this.filePattern = filePattern; + return asBuilder(); + } + + public B setAppend(final boolean append) { + this.append = append; + return asBuilder(); + } + + public B setPolicy(final TriggeringPolicy policy) { + this.policy = policy; + return asBuilder(); + } + + public B setStrategy(final RolloverStrategy strategy) { + this.strategy = strategy; + return asBuilder(); + } + + public B setAdvertise(final boolean advertise) { + this.advertise = advertise; + return asBuilder(); + } + + public B setAdvertiseURI(final String advertiseURI) { + this.advertiseURI = advertiseURI; + return asBuilder(); + } + + public B setFilePermissions(final String filePermissions) { + this.filePermissions = filePermissions; + return asBuilder(); + } + + public B setFileOwner(final String fileOwner) { + this.fileOwner = fileOwner; + return asBuilder(); + } + + public B setFileGroup(final String fileGroup) { + this.fileGroup = fileGroup; + return asBuilder(); + } + + /** + * @deprecated use {@link #setFileName(String)}. + */ + @Deprecated public B withFileName(final String fileName) { this.fileName = fileName; return asBuilder(); } + /** + * @deprecated use {@link #setFilePattern(String)}. + */ + @Deprecated public B withFilePattern(final String filePattern) { this.filePattern = filePattern; return asBuilder(); } + /** + * @deprecated use {@link #setAppend(boolean)}. + */ + @Deprecated public B withAppend(final boolean append) { this.append = append; return asBuilder(); } + /** + * @deprecated use {@link #setPolicy(TriggeringPolicy)}. + */ + @Deprecated public B withPolicy(final TriggeringPolicy policy) { this.policy = policy; return asBuilder(); } + /** + * @deprecated use {@link #setStrategy(RolloverStrategy)}. + */ + @Deprecated public B withStrategy(final RolloverStrategy strategy) { this.strategy = strategy; return asBuilder(); } + /** + * @deprecated use {@link #setAdvertise(boolean)}. + */ + @Deprecated public B withAdvertise(final boolean advertise) { this.advertise = advertise; return asBuilder(); } + /** + * @deprecated use {@link #setAdvertiseURI(String)}. + */ + @Deprecated public B withAdvertiseURI(final String advertiseURI) { this.advertiseURI = advertiseURI; return asBuilder(); } + /** + * @deprecated use {@link #setFilePermissions(String)}. + */ + @Deprecated public B withFilePermissions(final String filePermissions) { this.filePermissions = filePermissions; return asBuilder(); } + /** + * @deprecated use {@link #setFileOwner(String)}. + */ + @Deprecated public B withFileOwner(final String fileOwner) { this.fileOwner = fileOwner; return asBuilder(); } + /** + * @deprecated use {@link #setFileGroup(String)}. + */ + @Deprecated public B withFileGroup(final String fileGroup) { this.fileGroup = fileGroup; return asBuilder(); @@ -353,20 +443,20 @@ public static > RollingRandomAccessFileAppender createAppen final int bufferSize = Integers.parseInt(bufferSizeStr, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE); return RollingRandomAccessFileAppender.newBuilder() - .withAdvertise(isAdvertise) - .withAdvertiseURI(advertiseURI) - .withAppend(isAppend) - .withBufferSize(bufferSize) + .setAdvertise(isAdvertise) + .setAdvertiseURI(advertiseURI) + .setAppend(isAppend) + .setBufferSize(bufferSize) .setConfiguration(configuration) - .withFileName(fileName) - .withFilePattern(filePattern) + .setFileName(fileName) + .setFilePattern(filePattern) .setFilter(filter) .setIgnoreExceptions(isIgnoreExceptions) - .withImmediateFlush(isImmediateFlush) + .setImmediateFlush(isImmediateFlush) .setLayout(layout) .setName(name) - .withPolicy(policy) - .withStrategy(strategy) + .setPolicy(policy) + .setStrategy(strategy) .build(); } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptAppenderSelector.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptAppenderSelector.java index 200fa47ec7c..172963ad577 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptAppenderSelector.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptAppenderSelector.java @@ -118,21 +118,57 @@ public AbstractScript getScript() { return script; } + public Builder setAppenderNodeSet(@SuppressWarnings("hiding") final AppenderSet appenderSet) { + this.appenderSet = appenderSet; + return this; + } + + public Builder setConfiguration(@SuppressWarnings("hiding") final Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setName(@SuppressWarnings("hiding") final String name) { + this.name = name; + return this; + } + + public Builder setScript(@SuppressWarnings("hiding") final AbstractScript script) { + this.script = script; + return this; + } + + /** + * @deprecated use {@link #setAppenderNodeSet(AppenderSet)}. + */ + @Deprecated public Builder withAppenderNodeSet(@SuppressWarnings("hiding") final AppenderSet appenderSet) { this.appenderSet = appenderSet; return this; } + /** + * @deprecated use {@link #setConfiguration(Configuration)}. + */ + @Deprecated public Builder withConfiguration(@SuppressWarnings("hiding") final Configuration configuration) { this.configuration = configuration; return this; } + /** + * @deprecated use {@link #setName(String)}. + */ + @Deprecated public Builder withName(@SuppressWarnings("hiding") final String name) { this.name = name; return this; } + /** + * @deprecated use {@link #setScript(AbstractScript)}. + */ + @Deprecated public Builder withScript(@SuppressWarnings("hiding") final AbstractScript script) { this.script = script; return this; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/ColumnMapping.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/ColumnMapping.java index e1eedbc16f1..4982c5b05c2 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/ColumnMapping.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/ColumnMapping.java @@ -88,9 +88,9 @@ public static class Builder implements org.apache.logging.log4j.core.util.Builde public ColumnMapping build() { if (pattern != null) { layout = PatternLayout.newBuilder() - .withPattern(pattern) - .withConfiguration(configuration) - .withAlwaysWriteExceptions(false) + .setPattern(pattern) + .setConfiguration(configuration) + .setAlwaysWriteExceptions(false) .build(); } final Class columnType = type != null ? type : this.columnType; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java index 56605be97cc..9778ecfa6a1 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfig.java @@ -88,9 +88,9 @@ public ColumnConfig build() { if (isPattern) { final PatternLayout layout = PatternLayout.newBuilder() - .withPattern(pattern) - .withConfiguration(configuration) - .withAlwaysWriteExceptions(false) + .setPattern(pattern) + .setConfiguration(configuration) + .setAlwaysWriteExceptions(false) .build(); return new ColumnConfig(name, layout, null, false, isUnicode, isClob); } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/package-info.java index b0c7d3049f0..a18b7715e4f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/package-info.java @@ -18,7 +18,7 @@ * Log4j 2 Appenders. */ @Export -@Version("2.20.3") +@Version("2.26.0") package org.apache.logging.log4j.core.appender; import org.osgi.annotation.bundle.Export; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java index 728763433ed..de114aea5b7 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java @@ -169,7 +169,7 @@ public String getMax() { * @param max The maximum number of files to keep. * @return This builder for chaining convenience */ - public Builder withMax(final String max) { + public Builder setMax(final String max) { this.max = max; return this; } @@ -184,7 +184,7 @@ public String getMin() { * @param min The minimum number of files to keep. * @return This builder for chaining convenience */ - public Builder withMin(final String min) { + public Builder setMin(final String min) { this.min = min; return this; } @@ -200,7 +200,7 @@ public String getFileIndex() { * index. If set to "min", file renaming and the counter will follow the Fixed Window strategy. * @return This builder for chaining convenience */ - public Builder withFileIndex(final String fileIndex) { + public Builder setFileIndex(final String fileIndex) { this.fileIndex = fileIndex; return this; } @@ -215,7 +215,7 @@ public String getCompressionLevelStr() { * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files. * @return This builder for chaining convenience */ - public Builder withCompressionLevelStr(final String compressionLevelStr) { + public Builder setCompressionLevelStr(final String compressionLevelStr) { this.compressionLevelStr = compressionLevelStr; return this; } @@ -230,7 +230,7 @@ public Action[] getCustomActions() { * @param customActions custom actions to perform asynchronously after rollover * @return This builder for chaining convenience */ - public Builder withCustomActions(final Action[] customActions) { + public Builder setCustomActions(final Action[] customActions) { this.customActions = customActions; return this; } @@ -245,7 +245,7 @@ public boolean isStopCustomActionsOnError() { * @param stopCustomActionsOnError whether to stop executing asynchronous actions if an error occurs * @return This builder for chaining convenience */ - public Builder withStopCustomActionsOnError(final boolean stopCustomActionsOnError) { + public Builder setStopCustomActionsOnError(final boolean stopCustomActionsOnError) { this.stopCustomActionsOnError = stopCustomActionsOnError; return this; } @@ -260,7 +260,7 @@ public String getTempCompressedFilePattern() { * @param tempCompressedFilePattern File pattern of the working file pattern used during compression, if null no temporary file are used * @return This builder for chaining convenience */ - public Builder withTempCompressedFilePattern(final String tempCompressedFilePattern) { + public Builder setTempCompressedFilePattern(final String tempCompressedFilePattern) { this.tempCompressedFilePattern = tempCompressedFilePattern; return this; } @@ -275,6 +275,78 @@ public Configuration getConfig() { * @param config The Configuration. * @return This builder for chaining convenience */ + public Builder setConfig(final Configuration config) { + this.config = config; + return this; + } + + /** + * @deprecated use {@link #setMax(String)}. + */ + @Deprecated + public Builder withMax(final String max) { + this.max = max; + return this; + } + + /** + * @deprecated use {@link #setMin(String)}. + */ + @Deprecated + public Builder withMin(final String min) { + this.min = min; + return this; + } + + /** + * @deprecated use {@link #setFileIndex(String)}. + */ + @Deprecated + public Builder withFileIndex(final String fileIndex) { + this.fileIndex = fileIndex; + return this; + } + + /** + * @deprecated use {@link #setCompressionLevelStr(String)}. + */ + @Deprecated + public Builder withCompressionLevelStr(final String compressionLevelStr) { + this.compressionLevelStr = compressionLevelStr; + return this; + } + + /** + * @deprecated use {@link #setCustomActions(Action[])}. + */ + @Deprecated + public Builder withCustomActions(final Action[] customActions) { + this.customActions = customActions; + return this; + } + + /** + * @deprecated use {@link #setStopCustomActionsOnError(boolean)}. + */ + @Deprecated + public Builder withStopCustomActionsOnError(final boolean stopCustomActionsOnError) { + this.stopCustomActionsOnError = stopCustomActionsOnError; + return this; + } + + /** + * @deprecated use {@link #setTempCompressedFilePattern(String)}. + */ + @Deprecated + public Builder withTempCompressedFilePattern(final String tempCompressedFilePattern) { + this.tempCompressedFilePattern = tempCompressedFilePattern; + return this; + } + + /** + * @deprecated use {@link #setConfig(Configuration)}. + */ + @Deprecated public Builder withConfig(final Configuration config) { this.config = config; return this; @@ -313,13 +385,13 @@ public static DefaultRolloverStrategy createStrategy( final boolean stopCustomActionsOnError, @PluginConfiguration final Configuration config) { return DefaultRolloverStrategy.newBuilder() - .withMin(min) - .withMax(max) - .withFileIndex(fileIndex) - .withCompressionLevelStr(compressionLevelStr) - .withCustomActions(customActions) - .withStopCustomActionsOnError(stopCustomActionsOnError) - .withConfig(config) + .setMin(min) + .setMax(max) + .setFileIndex(fileIndex) + .setCompressionLevelStr(compressionLevelStr) + .setCustomActions(customActions) + .setStopCustomActionsOnError(stopCustomActionsOnError) + .setConfig(config) .build(); // @formatter:on } @@ -617,14 +689,14 @@ public RolloverDescription rollover(final RollingFileManager manager) throws Sec // Propagate POSIX attribute view to compressed file // @formatter:off final Action posixAttributeViewAction = PosixViewAttributeAction.newBuilder() - .withBasePath(compressedName) - .withFollowLinks(false) - .withMaxDepth(1) - .withPathConditions(PathCondition.EMPTY_ARRAY) - .withSubst(getStrSubstitutor()) - .withFilePermissions(manager.getFilePermissions()) - .withFileOwner(manager.getFileOwner()) - .withFileGroup(manager.getFileGroup()) + .setBasePath(compressedName) + .setFollowLinks(false) + .setMaxDepth(1) + .setPathConditions(PathCondition.EMPTY_ARRAY) + .setSubst(getStrSubstitutor()) + .setFilePermissions(manager.getFilePermissions()) + .setFileOwner(manager.getFileOwner()) + .setFileGroup(manager.getFileGroup()) .build(); // @formatter:on compressAction = new CompositeAction(Arrays.asList(compressAction, posixAttributeViewAction), false); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java index ea41918e4a5..67c1dded4b0 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DirectWriteRolloverStrategy.java @@ -115,7 +115,7 @@ public String getMaxFiles() { * @param maxFiles The maximum number of files that match the date portion of the pattern to keep. * @return This builder for chaining convenience */ - public Builder withMaxFiles(final String maxFiles) { + public Builder setMaxFiles(final String maxFiles) { this.maxFiles = maxFiles; return this; } @@ -130,7 +130,7 @@ public String getCompressionLevelStr() { * @param compressionLevelStr The compression level, 0 (less) through 9 (more); applies only to ZIP files. * @return This builder for chaining convenience */ - public Builder withCompressionLevelStr(final String compressionLevelStr) { + public Builder setCompressionLevelStr(final String compressionLevelStr) { this.compressionLevelStr = compressionLevelStr; return this; } @@ -145,7 +145,7 @@ public Action[] getCustomActions() { * @param customActions custom actions to perform asynchronously after rollover * @return This builder for chaining convenience */ - public Builder withCustomActions(final Action[] customActions) { + public Builder setCustomActions(final Action[] customActions) { this.customActions = customActions; return this; } @@ -160,7 +160,7 @@ public boolean isStopCustomActionsOnError() { * @param stopCustomActionsOnError whether to stop executing asynchronous actions if an error occurs * @return This builder for chaining convenience */ - public Builder withStopCustomActionsOnError(final boolean stopCustomActionsOnError) { + public Builder setStopCustomActionsOnError(final boolean stopCustomActionsOnError) { this.stopCustomActionsOnError = stopCustomActionsOnError; return this; } @@ -175,7 +175,7 @@ public String getTempCompressedFilePattern() { * @param tempCompressedFilePattern File pattern of the working file pattern used during compression, if null no temporary file are used * @return This builder for chaining convenience */ - public Builder withTempCompressedFilePattern(final String tempCompressedFilePattern) { + public Builder setTempCompressedFilePattern(final String tempCompressedFilePattern) { this.tempCompressedFilePattern = tempCompressedFilePattern; return this; } @@ -190,6 +190,60 @@ public Configuration getConfig() { * @param config The Configuration. * @return This builder for chaining convenience */ + public Builder setConfig(final Configuration config) { + this.config = config; + return this; + } + + /** + * @deprecated use {@link #setMaxFiles(String)}. + */ + @Deprecated + public Builder withMaxFiles(final String maxFiles) { + this.maxFiles = maxFiles; + return this; + } + + /** + * @deprecated use {@link #setCompressionLevelStr(String)}. + */ + @Deprecated + public Builder withCompressionLevelStr(final String compressionLevelStr) { + this.compressionLevelStr = compressionLevelStr; + return this; + } + + /** + * @deprecated use {@link #setCustomActions(Action[])}. + */ + @Deprecated + public Builder withCustomActions(final Action[] customActions) { + this.customActions = customActions; + return this; + } + + /** + * @deprecated use {@link #setStopCustomActionsOnError(boolean)}. + */ + @Deprecated + public Builder withStopCustomActionsOnError(final boolean stopCustomActionsOnError) { + this.stopCustomActionsOnError = stopCustomActionsOnError; + return this; + } + + /** + * @deprecated use {@link #setTempCompressedFilePattern(String)}. + */ + @Deprecated + public Builder withTempCompressedFilePattern(final String tempCompressedFilePattern) { + this.tempCompressedFilePattern = tempCompressedFilePattern; + return this; + } + + /** + * @deprecated use {@link #setConfig(Configuration)}. + */ + @Deprecated public Builder withConfig(final Configuration config) { this.config = config; return this; @@ -223,11 +277,11 @@ public static DirectWriteRolloverStrategy createStrategy( final boolean stopCustomActionsOnError, @PluginConfiguration final Configuration config) { return newBuilder() - .withMaxFiles(maxFiles) - .withCompressionLevelStr(compressionLevelStr) - .withCustomActions(customActions) - .withStopCustomActionsOnError(stopCustomActionsOnError) - .withConfig(config) + .setMaxFiles(maxFiles) + .setCompressionLevelStr(compressionLevelStr) + .setCustomActions(customActions) + .setStopCustomActionsOnError(stopCustomActionsOnError) + .setConfig(config) .build(); // @formatter:on } @@ -399,14 +453,14 @@ public RolloverDescription rollover(final RollingFileManager manager) throws Sec // Propagate POSIX attribute view to compressed file // @formatter:off final Action posixAttributeViewAction = PosixViewAttributeAction.newBuilder() - .withBasePath(compressedName) - .withFollowLinks(false) - .withMaxDepth(1) - .withPathConditions(PathCondition.EMPTY_ARRAY) - .withSubst(getStrSubstitutor()) - .withFilePermissions(manager.getFilePermissions()) - .withFileOwner(manager.getFileOwner()) - .withFileGroup(manager.getFileGroup()) + .setBasePath(compressedName) + .setFollowLinks(false) + .setMaxDepth(1) + .setPathConditions(PathCondition.EMPTY_ARRAY) + .setSubst(getStrSubstitutor()) + .setFilePermissions(manager.getFilePermissions()) + .setFileOwner(manager.getFileOwner()) + .setFileGroup(manager.getFileGroup()) .build(); // @formatter:on compressAction = new CompositeAction(Arrays.asList(compressAction, posixAttributeViewAction), false); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/TimeBasedTriggeringPolicy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/TimeBasedTriggeringPolicy.java index a761aa8312c..e29f819a28f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/TimeBasedTriggeringPolicy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/TimeBasedTriggeringPolicy.java @@ -62,16 +62,43 @@ public int getMaxRandomDelay() { return maxRandomDelay; } + public Builder setInterval(final int interval) { + this.interval = interval; + return this; + } + + public Builder setModulate(final boolean modulate) { + this.modulate = modulate; + return this; + } + + public Builder setMaxRandomDelay(final int maxRandomDelay) { + this.maxRandomDelay = maxRandomDelay; + return this; + } + + /** + * @deprecated use {@link #setInterval(int)}. + */ + @Deprecated public Builder withInterval(final int interval) { this.interval = interval; return this; } + /** + * @deprecated use {@link #setModulate(boolean)}. + */ + @Deprecated public Builder withModulate(final boolean modulate) { this.modulate = modulate; return this; } + /** + * @deprecated use {@link #setMaxRandomDelay(int)}. + */ + @Deprecated public Builder withMaxRandomDelay(final int maxRandomDelay) { this.maxRandomDelay = maxRandomDelay; return this; @@ -149,8 +176,8 @@ public boolean isTriggeringEvent(final LogEvent event) { public static TimeBasedTriggeringPolicy createPolicy( @PluginAttribute("interval") final String interval, @PluginAttribute("modulate") final String modulate) { return newBuilder() - .withInterval(Integers.parseInt(interval, 1)) - .withModulate(Boolean.parseBoolean(modulate)) + .setInterval(Integers.parseInt(interval, 1)) + .setModulate(Boolean.parseBoolean(modulate)) .build(); } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PosixViewAttributeAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PosixViewAttributeAction.java index 9e45b5bef5a..ef64a58a4bd 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PosixViewAttributeAction.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PosixViewAttributeAction.java @@ -162,7 +162,7 @@ public PosixViewAttributeAction build() { * @param configuration {@link AbstractPathAction#getStrSubstitutor()} * @return This builder */ - public Builder withConfiguration(final Configuration configuration) { + public Builder setConfiguration(final Configuration configuration) { this.configuration = configuration; return this; } @@ -173,7 +173,7 @@ public Builder withConfiguration(final Configuration configuration) { * @param subst {@link AbstractPathAction#getStrSubstitutor()} * @return This builder */ - public Builder withSubst(final StrSubstitutor subst) { + public Builder setSubst(final StrSubstitutor subst) { this.subst = subst; return this; } @@ -183,7 +183,7 @@ public Builder withSubst(final StrSubstitutor subst) { * @param basePath {@link AbstractPathAction#getBasePath()} * @return This builder */ - public Builder withBasePath(final String basePath) { + public Builder setBasePath(final String basePath) { this.basePath = basePath; return this; } @@ -193,7 +193,7 @@ public Builder withBasePath(final String basePath) { * @param followLinks Follow synonyms links * @return This builder */ - public Builder withFollowLinks(final boolean followLinks) { + public Builder setFollowLinks(final boolean followLinks) { this.followLinks = followLinks; return this; } @@ -203,7 +203,7 @@ public Builder withFollowLinks(final boolean followLinks) { * @param maxDepth Max search depth * @return This builder */ - public Builder withMaxDepth(final int maxDepth) { + public Builder setMaxDepth(final int maxDepth) { this.maxDepth = maxDepth; return this; } @@ -214,7 +214,7 @@ public Builder withMaxDepth(final int maxDepth) { * @param pathConditions {@link AbstractPathAction#getPathConditions()} * @return This builder */ - public Builder withPathConditions(final PathCondition[] pathConditions) { + public Builder setPathConditions(final PathCondition[] pathConditions) { this.pathConditions = pathConditions; return this; } @@ -228,7 +228,7 @@ public Builder withPathConditions(final PathCondition[] pathConditions) { * @param filePermissionsString Permissions to apply * @return This builder */ - public Builder withFilePermissionsString(final String filePermissionsString) { + public Builder setFilePermissionsString(final String filePermissionsString) { this.filePermissionsString = filePermissionsString; return this; } @@ -238,7 +238,7 @@ public Builder withFilePermissionsString(final String filePermissionsString) { * @param filePermissions Permissions to apply * @return This builder */ - public Builder withFilePermissions(final Set filePermissions) { + public Builder setFilePermissions(final Set filePermissions) { this.filePermissions = filePermissions; return this; } @@ -248,7 +248,7 @@ public Builder withFilePermissions(final Set filePermission * @param fileOwner File owner * @return This builder */ - public Builder withFileOwner(final String fileOwner) { + public Builder setFileOwner(final String fileOwner) { this.fileOwner = fileOwner; return this; } @@ -258,6 +258,96 @@ public Builder withFileOwner(final String fileOwner) { * @param fileGroup File group * @return This builder */ + public Builder setFileGroup(final String fileGroup) { + this.fileGroup = fileGroup; + return this; + } + + /** + * @deprecated use {@link #setConfiguration(Configuration)}. + */ + @Deprecated + public Builder withConfiguration(final Configuration configuration) { + this.configuration = configuration; + return this; + } + + /** + * @deprecated use {@link #setSubst(StrSubstitutor)}. + */ + @Deprecated + public Builder withSubst(final StrSubstitutor subst) { + this.subst = subst; + return this; + } + + /** + * @deprecated use {@link #setBasePath(String)}. + */ + @Deprecated + public Builder withBasePath(final String basePath) { + this.basePath = basePath; + return this; + } + + /** + * @deprecated use {@link #setFollowLinks(boolean)}. + */ + @Deprecated + public Builder withFollowLinks(final boolean followLinks) { + this.followLinks = followLinks; + return this; + } + + /** + * @deprecated use {@link #setMaxDepth(int)}. + */ + @Deprecated + public Builder withMaxDepth(final int maxDepth) { + this.maxDepth = maxDepth; + return this; + } + + /** + * @deprecated use {@link #setPathConditions(PathCondition[])}. + */ + @Deprecated + public Builder withPathConditions(final PathCondition[] pathConditions) { + this.pathConditions = pathConditions; + return this; + } + + /** + * @deprecated use {@link #setFilePermissionsString(String)}. + */ + @Deprecated + public Builder withFilePermissionsString(final String filePermissionsString) { + this.filePermissionsString = filePermissionsString; + return this; + } + + /** + * @deprecated use {@link #setFilePermissions(Set)}. + */ + @Deprecated + public Builder withFilePermissions(final Set filePermissions) { + this.filePermissions = filePermissions; + return this; + } + + /** + * @deprecated use {@link #setFileOwner(String)}. + */ + @Deprecated + public Builder withFileOwner(final String fileOwner) { + this.fileOwner = fileOwner; + return this; + } + + /** + * @deprecated use {@link #setFileGroup(String)}. + */ + @Deprecated public Builder withFileGroup(final String fileGroup) { this.fileGroup = fileGroup; return this; 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 4e9d1a1bb9d..37370530300 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.24.0") +@Version("2.26.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/appender/rolling/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/package-info.java index 3be84e0d2a6..9f4ea078048 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/package-info.java @@ -18,7 +18,7 @@ * Rolling File Appender and support classes. */ @Export -@Version("2.21.1") +@Version("2.26.0") package org.apache.logging.log4j.core.appender.rolling; import org.osgi.annotation.bundle.Export; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java index cb5a452ef27..692f174fb43 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java @@ -104,21 +104,57 @@ public Route[] getRoutes() { return routes; } + public Builder setConfiguration(@SuppressWarnings("hiding") final Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setPattern(@SuppressWarnings("hiding") final String pattern) { + this.pattern = pattern; + return this; + } + + public Builder setPatternScript(@SuppressWarnings("hiding") final AbstractScript patternScript) { + this.patternScript = patternScript; + return this; + } + + public Builder setRoutes(@SuppressWarnings("hiding") final Route[] routes) { + this.routes = routes; + return this; + } + + /** + * @deprecated use {@link #setConfiguration(Configuration)}. + */ + @Deprecated public Builder withConfiguration(@SuppressWarnings("hiding") final Configuration configuration) { this.configuration = configuration; return this; } + /** + * @deprecated use {@link #setPattern(String)}. + */ + @Deprecated public Builder withPattern(@SuppressWarnings("hiding") final String pattern) { this.pattern = pattern; return this; } + /** + * @deprecated use {@link #setPatternScript(AbstractScript)}. + */ + @Deprecated public Builder withPatternScript(@SuppressWarnings("hiding") final AbstractScript patternScript) { this.patternScript = patternScript; return this; } + /** + * @deprecated use {@link #setRoutes(Route[])}. + */ + @Deprecated public Builder withRoutes(@SuppressWarnings("hiding") final Route[] routes) { this.routes = routes; return this; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java index 14aadb1afb6..6a36e3e608e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java @@ -122,21 +122,56 @@ public PurgePolicy getPurgePolicy() { return purgePolicy; } + public B setRoutes(@SuppressWarnings("hiding") final Routes routes) { + this.routes = routes; + return asBuilder(); + } + + public B setDefaultRouteScript(@SuppressWarnings("hiding") final AbstractScript defaultRouteScript) { + this.defaultRouteScript = defaultRouteScript; + return asBuilder(); + } + + public B setRewritePolicy(@SuppressWarnings("hiding") final RewritePolicy rewritePolicy) { + this.rewritePolicy = rewritePolicy; + return asBuilder(); + } + + public void setPurgePolicy(@SuppressWarnings("hiding") final PurgePolicy purgePolicy) { + this.purgePolicy = purgePolicy; + } + + /** + * @deprecated use {@link #setRoutes(Routes)}. + */ + @Deprecated public B withRoutes(@SuppressWarnings("hiding") final Routes routes) { this.routes = routes; return asBuilder(); } + /** + * @deprecated use {@link #setDefaultRouteScript(AbstractScript)}. + */ + @Deprecated public B withDefaultRouteScript(@SuppressWarnings("hiding") final AbstractScript defaultRouteScript) { this.defaultRouteScript = defaultRouteScript; return asBuilder(); } + /** + * @deprecated use {@link #setRewritePolicy(RewritePolicy)}. + */ + @Deprecated public B withRewritePolicy(@SuppressWarnings("hiding") final RewritePolicy rewritePolicy) { this.rewritePolicy = rewritePolicy; return asBuilder(); } + /** + * @deprecated use {@link #setPurgePolicy(PurgePolicy)}. + */ + @Deprecated public void withPurgePolicy(@SuppressWarnings("hiding") final PurgePolicy purgePolicy) { this.purgePolicy = purgePolicy; } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java index b10a700d62b..044a76ea32b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java @@ -18,7 +18,7 @@ * Apache Flume Appender. Requires the user specifically include Flume and its dependencies. */ @Export -@Version("2.20.1") +@Version("2.26.0") package org.apache.logging.log4j.core.appender.routing; import org.osgi.annotation.bundle.Export; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java index 0a9be69d19a..3a9503588d6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java @@ -140,7 +140,7 @@ public boolean isAdditivity() { return additivity == null || additivity; } - public B withAdditivity(final boolean additivity) { + public B setAdditivity(final boolean additivity) { this.additivity = additivity; return asBuilder(); } @@ -149,7 +149,7 @@ public Level getLevel() { return level; } - public B withLevel(final Level level) { + public B setLevel(final Level level) { this.level = level; return asBuilder(); } @@ -158,7 +158,7 @@ public String getLevelAndRefs() { return levelAndRefs; } - public B withLevelAndRefs(final String levelAndRefs) { + public B setLevelAndRefs(final String levelAndRefs) { this.levelAndRefs = levelAndRefs; return asBuilder(); } @@ -167,7 +167,7 @@ public String getLoggerName() { return loggerName; } - public B withLoggerName(final String loggerName) { + public B setLoggerName(final String loggerName) { this.loggerName = loggerName; return asBuilder(); } @@ -176,7 +176,7 @@ public String getIncludeLocation() { return includeLocation; } - public B withIncludeLocation(final String includeLocation) { + public B setIncludeLocation(final String includeLocation) { this.includeLocation = includeLocation; return asBuilder(); } @@ -185,7 +185,7 @@ public AppenderRef[] getRefs() { return refs; } - public B withRefs(final AppenderRef[] refs) { + public B setRefs(final AppenderRef[] refs) { this.refs = refs; return asBuilder(); } @@ -194,7 +194,7 @@ public Property[] getProperties() { return properties; } - public B withProperties(final Property[] properties) { + public B setProperties(final Property[] properties) { this.properties = properties; return asBuilder(); } @@ -203,7 +203,7 @@ public Configuration getConfig() { return config; } - public B withConfig(final Configuration config) { + public B setConfig(final Configuration config) { this.config = config; return asBuilder(); } @@ -212,6 +212,84 @@ public Filter getFilter() { return filter; } + /** @since 2.25.0 */ + public B setFilter(final Filter filter) { + this.filter = filter; + return asBuilder(); + } + + /** + * @deprecated use {@link #setAdditivity(boolean)}. + */ + @Deprecated + public B withAdditivity(final boolean additivity) { + this.additivity = additivity; + return asBuilder(); + } + + /** + * @deprecated use {@link #setLevel(Level)}. + */ + @Deprecated + public B withLevel(final Level level) { + this.level = level; + return asBuilder(); + } + + /** + * @deprecated use {@link #setLevelAndRefs(String)}. + */ + @Deprecated + public B withLevelAndRefs(final String levelAndRefs) { + this.levelAndRefs = levelAndRefs; + return asBuilder(); + } + + /** + * @deprecated use {@link #setLoggerName(String)}. + */ + @Deprecated + public B withLoggerName(final String loggerName) { + this.loggerName = loggerName; + return asBuilder(); + } + + /** + * @deprecated use {@link #setIncludeLocation(String)}. + */ + @Deprecated + public B withIncludeLocation(final String includeLocation) { + this.includeLocation = includeLocation; + return asBuilder(); + } + + /** + * @deprecated use {@link #setRefs(AppenderRef[])}. + */ + @Deprecated + public B withRefs(final AppenderRef[] refs) { + this.refs = refs; + return asBuilder(); + } + + /** + * @deprecated use {@link #setProperties(Property[])}. + */ + @Deprecated + public B withProperties(final Property[] properties) { + this.properties = properties; + return asBuilder(); + } + + /** + * @deprecated use {@link #setConfig(Configuration)}. + */ + @Deprecated + public B withConfig(final Configuration config) { + this.config = config; + return asBuilder(); + } + /** * @deprecated Use {@link #setFilter(Filter)} instead */ @@ -226,12 +304,6 @@ public B withFilter(final Filter filter) { return setFilter(filter); } - /** @since 2.25.0 */ - public B setFilter(final Filter filter) { - this.filter = filter; - return asBuilder(); - } - @Override public LoggerConfig build() { final String name = loggerName.equals(ROOT) ? Strings.EMPTY : loggerName; @@ -879,7 +951,7 @@ public boolean isAdditivity() { return additivity; } - public B withAdditivity(final boolean additivity) { + public B setAdditivity(final boolean additivity) { this.additivity = additivity; return asBuilder(); } @@ -888,7 +960,7 @@ public Level getLevel() { return level; } - public B withLevel(final Level level) { + public B setLevel(final Level level) { this.level = level; return asBuilder(); } @@ -897,7 +969,7 @@ public String getLevelAndRefs() { return levelAndRefs; } - public B withLevelAndRefs(final String levelAndRefs) { + public B setLevelAndRefs(final String levelAndRefs) { this.levelAndRefs = levelAndRefs; return asBuilder(); } @@ -906,7 +978,7 @@ public String getIncludeLocation() { return includeLocation; } - public B withIncludeLocation(final String includeLocation) { + public B setIncludeLocation(final String includeLocation) { this.includeLocation = includeLocation; return asBuilder(); } @@ -915,7 +987,7 @@ public AppenderRef[] getRefs() { return refs; } - public B withRefs(final AppenderRef[] refs) { + public B setRefs(final AppenderRef[] refs) { this.refs = refs; return asBuilder(); } @@ -924,7 +996,7 @@ public Property[] getProperties() { return properties; } - public B withProperties(final Property[] properties) { + public B setProperties(final Property[] properties) { this.properties = properties; return asBuilder(); } @@ -933,7 +1005,7 @@ public Configuration getConfig() { return config; } - public B withConfig(final Configuration config) { + public B setConfig(final Configuration config) { this.config = config; return asBuilder(); } @@ -942,20 +1014,83 @@ public Filter getFilter() { return filter; } + /** @since 2.25.0 */ + public B setFilter(final Filter filter) { + this.filter = filter; + return asBuilder(); + } + /** - * @deprecated since 2.25.0. Use {@link #setFilter(Filter)} instead. + * @deprecated use {@link #setAdditivity(boolean)}. */ @Deprecated - public B withtFilter(final Filter filter) { - return setFilter(filter); + public B withAdditivity(final boolean additivity) { + this.additivity = additivity; + return asBuilder(); } - /** @since 2.25.0 */ - public B setFilter(final Filter filter) { - this.filter = filter; + /** + * @deprecated use {@link #setLevel(Level)}. + */ + @Deprecated + public B withLevel(final Level level) { + this.level = level; + return asBuilder(); + } + + /** + * @deprecated use {@link #setLevelAndRefs(String)}. + */ + @Deprecated + public B withLevelAndRefs(final String levelAndRefs) { + this.levelAndRefs = levelAndRefs; return asBuilder(); } + /** + * @deprecated use {@link #setIncludeLocation(String)}. + */ + @Deprecated + public B withIncludeLocation(final String includeLocation) { + this.includeLocation = includeLocation; + return asBuilder(); + } + + /** + * @deprecated use {@link #setRefs(AppenderRef[])}. + */ + @Deprecated + public B withRefs(final AppenderRef[] refs) { + this.refs = refs; + return asBuilder(); + } + + /** + * @deprecated use {@link #setProperties(Property[])}. + */ + @Deprecated + public B withProperties(final Property[] properties) { + this.properties = properties; + return asBuilder(); + } + + /** + * @deprecated use {@link #setConfig(Configuration)}. + */ + @Deprecated + public B withConfig(final Configuration config) { + this.config = config; + return asBuilder(); + } + + /** + * @deprecated since 2.25.0. Use {@link #setFilter(Filter)} instead. + */ + @Deprecated + public B withtFilter(final Filter filter) { + return setFilter(filter); + } + @Override public LoggerConfig build() { final LevelAndRefs container = LoggerConfig.getLevelAndRefs(level, refs, levelAndRefs, config); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/package-info.java index 3db1c7abd6b..b0dbdc1ea00 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/package-info.java @@ -18,7 +18,7 @@ * Configuration of Log4j 2. */ @Export -@Version("2.25.0") +@Version("2.26.0") package org.apache.logging.log4j.core.config; import org.osgi.annotation.bundle.Export; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java index 39458807f7e..9889a6a7c2b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java @@ -188,16 +188,16 @@ public GelfLayout build() { } if (messagePattern != null) { patternLayout = PatternLayout.newBuilder() - .withPattern(messagePattern) - .withAlwaysWriteExceptions(includeStacktrace) - .withConfiguration(getConfiguration()) + .setPattern(messagePattern) + .setAlwaysWriteExceptions(includeStacktrace) + .setConfiguration(getConfiguration()) .build(); } if (patternSelector != null) { patternLayout = PatternLayout.newBuilder() - .withPatternSelector(patternSelector) - .withAlwaysWriteExceptions(includeStacktrace) - .withConfiguration(getConfiguration()) + .setPatternSelector(patternSelector) + .setAlwaysWriteExceptions(includeStacktrace) + .setConfiguration(getConfiguration()) .build(); } return new GelfLayout( diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java index 5f6e4299277..b5328f809ea 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java @@ -313,15 +313,15 @@ public static PatternLayout createLayout( @PluginAttribute("header") final String headerPattern, @PluginAttribute("footer") final String footerPattern) { return newBuilder() - .withPattern(pattern) - .withPatternSelector(patternSelector) - .withConfiguration(config) - .withRegexReplacement(replace) - .withCharset(charset) - .withAlwaysWriteExceptions(alwaysWriteExceptions) - .withNoConsoleNoAnsi(noConsoleNoAnsi) - .withHeader(headerPattern) - .withFooter(footerPattern) + .setPattern(pattern) + .setPatternSelector(patternSelector) + .setConfiguration(config) + .setRegexReplacement(replace) + .setCharset(charset) + .setAlwaysWriteExceptions(alwaysWriteExceptions) + .setNoConsoleNoAnsi(noConsoleNoAnsi) + .setHeader(headerPattern) + .setFooter(footerPattern) .build(); } @@ -613,7 +613,7 @@ public static PatternLayout createDefaultLayout() { * @see #DEFAULT_CONVERSION_PATTERN Default conversion pattern */ public static PatternLayout createDefaultLayout(final Configuration configuration) { - return newBuilder().withConfiguration(configuration).build(); + return newBuilder().setConfiguration(configuration).build(); } /** @@ -668,7 +668,7 @@ private Builder() {} * @param pattern * The pattern. If not specified, defaults to DEFAULT_CONVERSION_PATTERN. */ - public Builder withPattern(final String pattern) { + public Builder setPattern(final String pattern) { this.pattern = pattern; return this; } @@ -677,7 +677,7 @@ public Builder withPattern(final String pattern) { * @param patternSelector * Allows different patterns to be used based on some selection criteria. */ - public Builder withPatternSelector(final PatternSelector patternSelector) { + public Builder setPatternSelector(final PatternSelector patternSelector) { this.patternSelector = patternSelector; return this; } @@ -686,7 +686,7 @@ public Builder withPatternSelector(final PatternSelector patternSelector) { * @param configuration * The Configuration. Some Converters require access to the Interpolator. */ - public Builder withConfiguration(final Configuration configuration) { + public Builder setConfiguration(final Configuration configuration) { this.configuration = configuration; return this; } @@ -695,7 +695,7 @@ public Builder withConfiguration(final Configuration configuration) { * @param regexReplacement * A Regex replacement */ - public Builder withRegexReplacement(final RegexReplacement regexReplacement) { + public Builder setRegexReplacement(final RegexReplacement regexReplacement) { this.regexReplacement = regexReplacement; return this; } @@ -704,7 +704,7 @@ public Builder withRegexReplacement(final RegexReplacement regexReplacement) { * @param charset * The character set. The platform default is used if not specified. */ - public Builder withCharset(final Charset charset) { + public Builder setCharset(final Charset charset) { // LOG4J2-783 if null, use platform default by default if (charset != null) { this.charset = charset; @@ -716,7 +716,7 @@ public Builder withCharset(final Charset charset) { * @param alwaysWriteExceptions * If {@code "true"} (default) exceptions are always written even if the pattern contains no exception tokens. */ - public Builder withAlwaysWriteExceptions(final boolean alwaysWriteExceptions) { + public Builder setAlwaysWriteExceptions(final boolean alwaysWriteExceptions) { this.alwaysWriteExceptions = alwaysWriteExceptions; return this; } @@ -725,7 +725,7 @@ public Builder withAlwaysWriteExceptions(final boolean alwaysWriteExceptions) { * @param disableAnsi * If {@code true}, do not output ANSI escape codes. */ - public Builder withDisableAnsi(final boolean disableAnsi) { + public Builder setDisableAnsi(final boolean disableAnsi) { this.disableAnsi = disableAnsi; return this; } @@ -734,7 +734,7 @@ public Builder withDisableAnsi(final boolean disableAnsi) { * @param noConsoleNoAnsi * If {@code "true"} (default is false) and {@link System#console()} is null, do not output ANSI escape codes */ - public Builder withNoConsoleNoAnsi(final boolean noConsoleNoAnsi) { + public Builder setNoConsoleNoAnsi(final boolean noConsoleNoAnsi) { this.noConsoleNoAnsi = noConsoleNoAnsi; return this; } @@ -743,7 +743,7 @@ public Builder withNoConsoleNoAnsi(final boolean noConsoleNoAnsi) { * @param header * The header to place at the top of the document, once. */ - public Builder withHeader(final String header) { + public Builder setHeader(final String header) { this.header = header; return this; } @@ -752,6 +752,99 @@ public Builder withHeader(final String header) { * @param footer * The footer to place at the bottom of the document, once. */ + public Builder setFooter(final String footer) { + this.footer = footer; + return this; + } + + /** + * @deprecated use {@link #setPattern(String)}. + */ + @Deprecated + public Builder withPattern(final String pattern) { + this.pattern = pattern; + return this; + } + + /** + * @deprecated use {@link #setPatternSelector(PatternSelector)}. + */ + @Deprecated + public Builder withPatternSelector(final PatternSelector patternSelector) { + this.patternSelector = patternSelector; + return this; + } + + /** + * @deprecated use {@link #setConfiguration(Configuration)}. + */ + @Deprecated + public Builder withConfiguration(final Configuration configuration) { + this.configuration = configuration; + return this; + } + + /** + * @deprecated use {@link #setRegexReplacement(RegexReplacement)}. + */ + @Deprecated + public Builder withRegexReplacement(final RegexReplacement regexReplacement) { + this.regexReplacement = regexReplacement; + return this; + } + + /** + * @deprecated use {@link #setCharset(Charset)}. + */ + @Deprecated + public Builder withCharset(final Charset charset) { + // LOG4J2-783 if null, use platform default by default + if (charset != null) { + this.charset = charset; + } + return this; + } + + /** + * @deprecated use {@link #setAlwaysWriteExceptions(boolean)}. + */ + @Deprecated + public Builder withAlwaysWriteExceptions(final boolean alwaysWriteExceptions) { + this.alwaysWriteExceptions = alwaysWriteExceptions; + return this; + } + + /** + * @deprecated use {@link #setDisableAnsi(boolean)}. + */ + @Deprecated + public Builder withDisableAnsi(final boolean disableAnsi) { + this.disableAnsi = disableAnsi; + return this; + } + + /** + * @deprecated use {@link #setNoConsoleNoAnsi(boolean)}. + */ + @Deprecated + public Builder withNoConsoleNoAnsi(final boolean noConsoleNoAnsi) { + this.noConsoleNoAnsi = noConsoleNoAnsi; + return this; + } + + /** + * @deprecated use {@link #setHeader(String)}. + */ + @Deprecated + public Builder withHeader(final String header) { + this.header = header; + return this; + } + + /** + * @deprecated use {@link #setFooter(String)}. + */ + @Deprecated public Builder withFooter(final String footer) { this.footer = footer; return this; diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/package-info.java index 1a93726007f..6fc5dbb1a12 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/package-info.java @@ -22,7 +22,7 @@ * {@link org.apache.logging.log4j.core.Layout#ELEMENT_TYPE layout}. */ @Export -@Version("2.25.0") +@Version("2.26.0") package org.apache.logging.log4j.core.layout; import org.osgi.annotation.bundle.Export; diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PatternResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PatternResolver.java index 249c24a44a1..cb1ec2cf26a 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PatternResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PatternResolver.java @@ -62,10 +62,10 @@ public final class PatternResolver implements EventResolver { final boolean stackTraceEnabled = Optional.ofNullable(config.getBoolean("stackTraceEnabled")).orElse(context.isStackTraceEnabled()); final PatternLayout patternLayout = PatternLayout.newBuilder() - .withConfiguration(context.getConfiguration()) - .withCharset(context.getCharset()) - .withPattern(pattern) - .withAlwaysWriteExceptions(stackTraceEnabled) + .setConfiguration(context.getConfiguration()) + .setCharset(context.getCharset()) + .setPattern(pattern) + .setAlwaysWriteExceptions(stackTraceEnabled) .build(); this.emitter = (final StringBuilder stringBuilder, final LogEvent logEvent) -> patternLayout.serialize(logEvent, stringBuilder); diff --git a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark2.java b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark2.java index 3c16cae0527..f898dab7b59 100644 --- a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark2.java +++ b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextBenchmark2.java @@ -145,8 +145,8 @@ public void setup() { context = (LoggerContext) LogManager.getContext(false); Configuration config = context.getConfiguration(); PatternLayout layout = PatternLayout.newBuilder() - .withConfiguration(config) - .withPattern("%X %m%n") + .setConfiguration(config) + .setPattern("%X %m%n") .build(); appender = StringAppender.createAppender("String", layout, null); appender.start(); @@ -183,8 +183,8 @@ public void setup() { context = (LoggerContext) LogManager.getContext(false); Configuration config = context.getConfiguration(); PatternLayout layout = PatternLayout.newBuilder() - .withConfiguration(config) - .withPattern("%X %m%n") + .setConfiguration(config) + .setPattern("%X %m%n") .build(); appender = StringAppender.createAppender("String", layout, null); appender.start(); diff --git a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/instant/InstantPatternFormatterImpactBenchmark.java b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/instant/InstantPatternFormatterImpactBenchmark.java index 292d1f041a9..ce93495befa 100644 --- a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/instant/InstantPatternFormatterImpactBenchmark.java +++ b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/instant/InstantPatternFormatterImpactBenchmark.java @@ -61,10 +61,10 @@ private static List createLogEvents(final BiFunction + + + + Deprecated withers in builder classes in favor of setters. This change improves API consistency with 3.x and helps users adapt to the upcoming changes. + +