Skip to content

Deprecate withers in 2.x in favor of setters #3756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,25 @@ private <T extends Log4j1Configuration> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void testSetPriorityNull() {
void testClassName() {
final Category category = Category.getInstance("TestCategory");
final Layout<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void testConsoleStreamManagerDoesNotClose(
try {
systemSetter.systemSet(psMock);
final Layout<String> layout =
PatternLayout.newBuilder().withAlwaysWriteExceptions(true).build();
PatternLayout.newBuilder().setAlwaysWriteExceptions(true).build();
final ConsoleAppender app = ConsoleAppender.newBuilder()
.setLayout(layout)
.setTarget(targetName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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 {
Expand Down Expand Up @@ -130,20 +130,20 @@ void testFileUserGroupAPI(final String filePermissions, final int fileIndex) thr
assertNotNull(group);

final Layout<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ void testLazyCreate(final boolean createOnDemand) {
final Layout<String> 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());
Expand All @@ -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();
}

Expand All @@ -110,14 +110,14 @@ void testSmallestBufferSize(final boolean createOnDemand) throws Exception {
final Layout<String> 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 {
Expand Down Expand Up @@ -243,14 +243,14 @@ private static void writer(
final Layout<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading