Merge pull request #46372 from vy
* pr/46372: Polish "Avoid using deprecated Log4J constructors" Avoid using deprecated Log4J constructors Closes gh-46372
This commit is contained in:
commit
7a5e77fe67
|
@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.config.Configuration;
|
||||||
import org.apache.logging.log4j.core.config.plugins.Plugin;
|
import org.apache.logging.log4j.core.config.plugins.Plugin;
|
||||||
import org.apache.logging.log4j.core.pattern.ConverterKeys;
|
import org.apache.logging.log4j.core.pattern.ConverterKeys;
|
||||||
import org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter;
|
import org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter;
|
||||||
|
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
|
||||||
import org.apache.logging.log4j.core.pattern.PatternConverter;
|
import org.apache.logging.log4j.core.pattern.PatternConverter;
|
||||||
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
|
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
@ -35,25 +36,33 @@ import org.jspecify.annotations.Nullable;
|
||||||
*/
|
*/
|
||||||
@Plugin(name = "ExtendedWhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY)
|
@Plugin(name = "ExtendedWhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY)
|
||||||
@ConverterKeys({ "xwEx", "xwThrowable", "xwException" })
|
@ConverterKeys({ "xwEx", "xwThrowable", "xwException" })
|
||||||
public final class ExtendedWhitespaceThrowablePatternConverter extends ThrowablePatternConverter {
|
public final class ExtendedWhitespaceThrowablePatternConverter extends LogEventPatternConverter {
|
||||||
|
|
||||||
private final ExtendedThrowablePatternConverter delegate;
|
private final ExtendedThrowablePatternConverter delegate;
|
||||||
|
|
||||||
|
private final String separator;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // https://github.com/apache/logging-log4j2/issues/3809
|
@SuppressWarnings("deprecation") // https://github.com/apache/logging-log4j2/issues/3809
|
||||||
private ExtendedWhitespaceThrowablePatternConverter(Configuration configuration, @Nullable String[] options) {
|
private ExtendedWhitespaceThrowablePatternConverter(Configuration configuration, @Nullable String[] options) {
|
||||||
super("WhitespaceExtendedThrowable", "throwable", options, configuration);
|
super("WhitespaceExtendedThrowable", "throwable");
|
||||||
this.delegate = ExtendedThrowablePatternConverter.newInstance(configuration, options);
|
this.delegate = ExtendedThrowablePatternConverter.newInstance(configuration, options);
|
||||||
|
this.separator = this.delegate.getOptions().getSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void format(LogEvent event, StringBuilder buffer) {
|
public void format(LogEvent event, StringBuilder buffer) {
|
||||||
if (event.getThrown() != null) {
|
if (event.getThrown() != null) {
|
||||||
buffer.append(this.options.getSeparator());
|
buffer.append(this.separator);
|
||||||
this.delegate.format(event, buffer);
|
this.delegate.format(event, buffer);
|
||||||
buffer.append(this.options.getSeparator());
|
buffer.append(this.separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlesThrowable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the class. Required by Log4J2.
|
* Creates a new instance of the class. Required by Log4J2.
|
||||||
* @param configuration current configuration
|
* @param configuration current configuration
|
||||||
|
|
|
@ -20,6 +20,8 @@ import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.config.Configuration;
|
import org.apache.logging.log4j.core.config.Configuration;
|
||||||
import org.apache.logging.log4j.core.config.plugins.Plugin;
|
import org.apache.logging.log4j.core.config.plugins.Plugin;
|
||||||
import org.apache.logging.log4j.core.pattern.ConverterKeys;
|
import org.apache.logging.log4j.core.pattern.ConverterKeys;
|
||||||
|
import org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter;
|
||||||
|
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
|
||||||
import org.apache.logging.log4j.core.pattern.PatternConverter;
|
import org.apache.logging.log4j.core.pattern.PatternConverter;
|
||||||
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
|
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
@ -33,22 +35,33 @@ import org.jspecify.annotations.Nullable;
|
||||||
*/
|
*/
|
||||||
@Plugin(name = "WhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY)
|
@Plugin(name = "WhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY)
|
||||||
@ConverterKeys({ "wEx", "wThrowable", "wException" })
|
@ConverterKeys({ "wEx", "wThrowable", "wException" })
|
||||||
public final class WhitespaceThrowablePatternConverter extends ThrowablePatternConverter {
|
public final class WhitespaceThrowablePatternConverter extends LogEventPatternConverter {
|
||||||
|
|
||||||
|
private final ExtendedThrowablePatternConverter delegate;
|
||||||
|
|
||||||
|
private final String separator;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // https://github.com/apache/logging-log4j2/issues/3809
|
@SuppressWarnings("deprecation") // https://github.com/apache/logging-log4j2/issues/3809
|
||||||
private WhitespaceThrowablePatternConverter(Configuration configuration, @Nullable String[] options) {
|
private WhitespaceThrowablePatternConverter(Configuration configuration, @Nullable String[] options) {
|
||||||
super("WhitespaceThrowable", "throwable", options, configuration);
|
super("WhitespaceThrowable", "throwable");
|
||||||
|
this.delegate = ExtendedThrowablePatternConverter.newInstance(configuration, options);
|
||||||
|
this.separator = this.delegate.getOptions().getSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void format(LogEvent event, StringBuilder buffer) {
|
public void format(LogEvent event, StringBuilder buffer) {
|
||||||
if (event.getThrown() != null) {
|
if (event.getThrown() != null) {
|
||||||
buffer.append(this.options.getSeparator());
|
buffer.append(this.separator);
|
||||||
super.format(event, buffer);
|
this.delegate.format(event, buffer);
|
||||||
buffer.append(this.options.getSeparator());
|
buffer.append(this.separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlesThrowable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the class. Required by Log4J2.
|
* Creates a new instance of the class. Required by Log4J2.
|
||||||
* @param configuration current configuration
|
* @param configuration current configuration
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.logging.log4j2;
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
||||||
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
|
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
|
||||||
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
|
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
class ExtendedWhitespaceThrowablePatternConverterTests {
|
class ExtendedWhitespaceThrowablePatternConverterTests {
|
||||||
|
|
||||||
private final ThrowablePatternConverter converter = ExtendedWhitespaceThrowablePatternConverter
|
private final LogEventPatternConverter converter = ExtendedWhitespaceThrowablePatternConverter
|
||||||
.newInstance(new DefaultConfiguration(), new String[] {});
|
.newInstance(new DefaultConfiguration(), new String[] {});
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.logging.log4j2;
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
||||||
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
|
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
|
||||||
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
|
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
class WhitespaceThrowablePatternConverterTests {
|
class WhitespaceThrowablePatternConverterTests {
|
||||||
|
|
||||||
private final ThrowablePatternConverter converter = WhitespaceThrowablePatternConverter
|
private final LogEventPatternConverter converter = WhitespaceThrowablePatternConverter
|
||||||
.newInstance(new DefaultConfiguration(), new String[] {});
|
.newInstance(new DefaultConfiguration(), new String[] {});
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue