Re-apply the upgrade to Log4j2 2.25.1
See gh-46372 See gh-46334
This commit is contained in:
parent
5cec09dd02
commit
b7695200a9
|
@ -79,4 +79,7 @@
|
||||||
<suppress files="EntityManagerFactoryBuilder\.java" checks="NoWhitespaceBefore" message="'...' is preceded with whitespace"/>
|
<suppress files="EntityManagerFactoryBuilder\.java" checks="NoWhitespaceBefore" message="'...' is preceded with whitespace"/>
|
||||||
<suppress files="DockerApi\.java" checks="NoWhitespaceBefore" message="'...' is preceded with whitespace"/>
|
<suppress files="DockerApi\.java" checks="NoWhitespaceBefore" message="'...' is preceded with whitespace"/>
|
||||||
<suppress files="InvocationContext\.java" checks="NoWhitespaceBefore" message="'...' is preceded with whitespace"/>
|
<suppress files="InvocationContext\.java" checks="NoWhitespaceBefore" message="'...' is preceded with whitespace"/>
|
||||||
|
<!-- https://github.com/apache/logging-log4j2/issues/2769#issuecomment-3049020222 -->
|
||||||
|
<suppress files="SpringProfileArbiter\.java" checks="SpringMethodVisibility"/>
|
||||||
|
<suppress files="StructuredLogLayout\.java" checks="SpringMethodVisibility"/>
|
||||||
</suppressions>
|
</suppressions>
|
||||||
|
|
|
@ -87,6 +87,12 @@ tasks.named("checkFormatMain") {
|
||||||
source(fileTree("src/main/javaTemplates"))
|
source(fileTree("src/main/javaTemplates"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.named("compileJava") {
|
||||||
|
// Provide the project coordinates to the `GraalVmProcessor`:
|
||||||
|
options.compilerArgs << '-Alog4j.graalvm.groupId=org.springframework.boot'
|
||||||
|
options.compilerArgs << '-Alog4j.graalvm.artifactId=spring-boot-log4j'
|
||||||
|
}
|
||||||
|
|
||||||
plugins.withType(EclipsePlugin) {
|
plugins.withType(EclipsePlugin) {
|
||||||
eclipse {
|
eclipse {
|
||||||
synchronizationTasks syncJavaTemplates
|
synchronizationTasks syncJavaTemplates
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.TreeSet;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.Marker;
|
import org.apache.logging.log4j.Marker;
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.impl.ThrowableProxy;
|
|
||||||
import org.apache.logging.log4j.core.time.Instant;
|
import org.apache.logging.log4j.core.time.Instant;
|
||||||
import org.apache.logging.log4j.util.ReadOnlyStringMap;
|
import org.apache.logging.log4j.util.ReadOnlyStringMap;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
@ -70,13 +69,13 @@ class ElasticCommonSchemaStructuredLogFormatter extends JsonWriterStructuredLogF
|
||||||
members.add("message", LogEvent::getMessage).as(StructuredMessage::get);
|
members.add("message", LogEvent::getMessage).as(StructuredMessage::get);
|
||||||
members.from(LogEvent::getContextData)
|
members.from(LogEvent::getContextData)
|
||||||
.usingPairs(contextPairs.nested(ElasticCommonSchemaStructuredLogFormatter::addContextDataPairs));
|
.usingPairs(contextPairs.nested(ElasticCommonSchemaStructuredLogFormatter::addContextDataPairs));
|
||||||
members.from(LogEvent::getThrownProxy).whenNotNull().usingMembers((thrownProxyMembers) -> {
|
members.from(LogEvent::getThrown)
|
||||||
thrownProxyMembers.add("error").usingMembers((error) -> {
|
.whenNotNull()
|
||||||
error.add("type", ThrowableProxy::getThrowable).whenNotNull().as(ObjectUtils::nullSafeClassName);
|
.usingMembers((thrownMembers) -> thrownMembers.add("error").usingMembers((error) -> {
|
||||||
error.add("message", ThrowableProxy::getMessage);
|
error.add("type", ObjectUtils::nullSafeClassName);
|
||||||
|
error.add("message", Throwable::getMessage);
|
||||||
error.add("stack_trace", extractor::stackTrace);
|
error.add("stack_trace", extractor::stackTrace);
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
members.add("tags", LogEvent::getMarker)
|
members.add("tags", LogEvent::getMarker)
|
||||||
.whenNotNull()
|
.whenNotNull()
|
||||||
.as(ElasticCommonSchemaStructuredLogFormatter::getMarkers)
|
.as(ElasticCommonSchemaStructuredLogFormatter::getMarkers)
|
||||||
|
|
|
@ -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,24 +36,32 @@ 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 ExtendedWhitespaceThrowablePatternConverter(Configuration configuration, String @Nullable [] options) {
|
private final String separator;
|
||||||
super("WhitespaceExtendedThrowable", "throwable", options, configuration);
|
|
||||||
|
private ExtendedWhitespaceThrowablePatternConverter(Configuration configuration, @Nullable String[] options) {
|
||||||
|
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
|
||||||
|
@ -61,7 +70,7 @@ public final class ExtendedWhitespaceThrowablePatternConverter extends Throwable
|
||||||
* @return a new {@code WhitespaceThrowablePatternConverter}
|
* @return a new {@code WhitespaceThrowablePatternConverter}
|
||||||
*/
|
*/
|
||||||
public static ExtendedWhitespaceThrowablePatternConverter newInstance(Configuration configuration,
|
public static ExtendedWhitespaceThrowablePatternConverter newInstance(Configuration configuration,
|
||||||
String @Nullable [] options) {
|
@Nullable String[] options) {
|
||||||
return new ExtendedWhitespaceThrowablePatternConverter(configuration, options);
|
return new ExtendedWhitespaceThrowablePatternConverter(configuration, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.boot.logging.log4j2;
|
package org.springframework.boot.logging.log4j2;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.impl.ThrowableProxy;
|
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
import org.slf4j.event.LoggingEvent;
|
import org.slf4j.event.LoggingEvent;
|
||||||
|
|
||||||
import org.springframework.boot.logging.StackTracePrinter;
|
import org.springframework.boot.logging.StackTracePrinter;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions to extract items from {@link LoggingEvent}.
|
* Functions to extract items from {@link LoggingEvent}.
|
||||||
|
@ -42,19 +43,23 @@ class Extractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable String stackTrace(LogEvent event) {
|
@Nullable String stackTrace(LogEvent event) {
|
||||||
return stackTrace(event.getThrownProxy());
|
return stackTrace(event.getThrown());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable String stackTrace(@Nullable ThrowableProxy throwableProxy) {
|
@Nullable String stackTrace(@Nullable Throwable throwable) {
|
||||||
if (throwableProxy == null) {
|
if (throwable == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this.stackTracePrinter != null) {
|
if (this.stackTracePrinter != null) {
|
||||||
Throwable throwable = throwableProxy.getThrowable();
|
|
||||||
Assert.state(throwable != null, "Proxy must return Throwable in order to print exception");
|
|
||||||
return this.stackTracePrinter.printStackTraceToString(throwable);
|
return this.stackTracePrinter.printStackTraceToString(throwable);
|
||||||
}
|
}
|
||||||
return throwableProxy.getExtendedStackTraceAsString();
|
return printStackTrace(throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String printStackTrace(Throwable throwable) {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
throwable.printStackTrace(new PrintWriter(stringWriter));
|
||||||
|
return stringWriter.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,11 +98,11 @@ class GraylogExtendedLogFormatStructuredLogFormatter extends JsonWriterStructure
|
||||||
.whenNot(mapIsEmpty)
|
.whenNot(mapIsEmpty)
|
||||||
.usingPairs(contextPairs.flat(additionalFieldJoiner(),
|
.usingPairs(contextPairs.flat(additionalFieldJoiner(),
|
||||||
GraylogExtendedLogFormatStructuredLogFormatter::addContextDataPairs));
|
GraylogExtendedLogFormatStructuredLogFormatter::addContextDataPairs));
|
||||||
Function<@Nullable LogEvent, @Nullable Object> getThrownProxy = (event) -> (event != null)
|
Function<@Nullable LogEvent, @Nullable Object> getThrown = (event) -> (event != null) ? event.getThrown()
|
||||||
? event.getThrownProxy() : null;
|
: null;
|
||||||
members.add()
|
members.add()
|
||||||
.whenNotNull(getThrownProxy)
|
.whenNotNull(getThrown)
|
||||||
.usingMembers((thrownProxyMembers) -> throwableMembers(thrownProxyMembers, extractor));
|
.usingMembers((thrownMembers) -> throwableMembers(thrownMembers, extractor));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getMessageText(Message message) {
|
private static String getMessageText(Message message) {
|
||||||
|
@ -134,11 +134,9 @@ class GraylogExtendedLogFormatStructuredLogFormatter extends JsonWriterStructure
|
||||||
|
|
||||||
private static void throwableMembers(Members<LogEvent> members, Extractor extractor) {
|
private static void throwableMembers(Members<LogEvent> members, Extractor extractor) {
|
||||||
members.add("full_message", extractor::messageAndStackTrace);
|
members.add("full_message", extractor::messageAndStackTrace);
|
||||||
members.add("_error_type", (event) -> event.getThrownProxy().getThrowable())
|
members.add("_error_type", LogEvent::getThrown).whenNotNull().as(ObjectUtils::nullSafeClassName);
|
||||||
.whenNotNull()
|
|
||||||
.as(ObjectUtils::nullSafeClassName);
|
|
||||||
members.add("_error_stack_trace", extractor::stackTrace);
|
members.add("_error_stack_trace", extractor::stackTrace);
|
||||||
members.add("_error_message", (event) -> event.getThrownProxy().getMessage());
|
members.add("_error_message", (event) -> event.getThrown().getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addContextDataPairs(ContextPairs.Pairs<ReadOnlyStringMap> contextPairs) {
|
private static void addContextDataPairs(ContextPairs.Pairs<ReadOnlyStringMap> contextPairs) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ class LogstashStructuredLogFormatter extends JsonWriterStructuredLogFormatter<Lo
|
||||||
.whenNotNull()
|
.whenNotNull()
|
||||||
.as(LogstashStructuredLogFormatter::getMarkers)
|
.as(LogstashStructuredLogFormatter::getMarkers)
|
||||||
.whenNot(collectionIsEmpty);
|
.whenNot(collectionIsEmpty);
|
||||||
members.add("stack_trace", LogEvent::getThrownProxy).whenNotNull().as(extractor::stackTrace);
|
members.add("stack_trace", LogEvent::getThrown).whenNotNull().as(extractor::stackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String asTimestamp(Instant instant) {
|
private static String asTimestamp(Instant instant) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ final class SpringProfileArbiter implements Arbiter {
|
||||||
* @return this
|
* @return this
|
||||||
* @see Profiles#of(String...)
|
* @see Profiles#of(String...)
|
||||||
*/
|
*/
|
||||||
Builder setName(String name) {
|
public Builder setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,12 +87,12 @@ final class StructuredLogLayout extends AbstractStringLayout {
|
||||||
@SuppressWarnings("NullAway.Init")
|
@SuppressWarnings("NullAway.Init")
|
||||||
private String charset = StandardCharsets.UTF_8.name();
|
private String charset = StandardCharsets.UTF_8.name();
|
||||||
|
|
||||||
Builder setFormat(String format) {
|
public Builder setFormat(String format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder setCharset(String charset) {
|
public Builder setCharset(String charset) {
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,21 +35,32 @@ 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 WhitespaceThrowablePatternConverter(Configuration configuration, String @Nullable [] options) {
|
private final ExtendedThrowablePatternConverter delegate;
|
||||||
super("WhitespaceThrowable", "throwable", options, configuration);
|
|
||||||
|
private final String separator;
|
||||||
|
|
||||||
|
private WhitespaceThrowablePatternConverter(Configuration configuration, @Nullable String[] options) {
|
||||||
|
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
|
||||||
|
@ -56,7 +69,7 @@ public final class WhitespaceThrowablePatternConverter extends ThrowablePatternC
|
||||||
* @return a new {@code WhitespaceThrowablePatternConverter}
|
* @return a new {@code WhitespaceThrowablePatternConverter}
|
||||||
*/
|
*/
|
||||||
public static WhitespaceThrowablePatternConverter newInstance(Configuration configuration,
|
public static WhitespaceThrowablePatternConverter newInstance(Configuration configuration,
|
||||||
String @Nullable [] options) {
|
@Nullable String[] options) {
|
||||||
return new WhitespaceThrowablePatternConverter(configuration, options);
|
return new WhitespaceThrowablePatternConverter(configuration, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,13 +101,14 @@ class ElasticCommonSchemaStructuredLogFormatterTests extends AbstractStructuredL
|
||||||
expectedError.put("message", "Boom");
|
expectedError.put("message", "Boom");
|
||||||
assertThat(error).containsAllEntriesOf(expectedError);
|
assertThat(error).containsAllEntriesOf(expectedError);
|
||||||
String stackTrace = (String) error.get("stack_trace");
|
String stackTrace = (String) error.get("stack_trace");
|
||||||
assertThat(stackTrace).startsWith(
|
assertThat(stackTrace)
|
||||||
"""
|
.startsWith(String.format("java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2."
|
||||||
java.lang.RuntimeException: Boom
|
+ "ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException"));
|
||||||
\tat org.springframework.boot.logging.log4j2.ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException""");
|
assertThat(json).contains(String
|
||||||
assertThat(json).contains(
|
.format("java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2."
|
||||||
"""
|
+ "ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException")
|
||||||
java.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.ElasticCommonSchemaStructuredLogFormatterTests.shouldFormatException""");
|
.replace("\n", "\\n")
|
||||||
|
.replace("\r", "\\r"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
||||||
|
@ -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
|
||||||
|
|
|
@ -136,21 +136,18 @@ class GraylogExtendedLogFormatStructuredLogFormatterTests extends AbstractStruct
|
||||||
String fullMessage = (String) deserialized.get("full_message");
|
String fullMessage = (String) deserialized.get("full_message");
|
||||||
String stackTrace = (String) deserialized.get("_error_stack_trace");
|
String stackTrace = (String) deserialized.get("_error_stack_trace");
|
||||||
assertThat(fullMessage).startsWith(
|
assertThat(fullMessage).startsWith(
|
||||||
"""
|
"message\n\njava.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"
|
||||||
message
|
.formatted());
|
||||||
|
|
||||||
java.lang.RuntimeException: Boom
|
|
||||||
\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException""");
|
|
||||||
assertThat(stackTrace).startsWith(
|
|
||||||
"""
|
|
||||||
java.lang.RuntimeException: Boom
|
|
||||||
\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException""");
|
|
||||||
|
|
||||||
assertThat(deserialized)
|
assertThat(deserialized)
|
||||||
.containsAllEntriesOf(map("_error_type", "java.lang.RuntimeException", "_error_message", "Boom"));
|
.containsAllEntriesOf(map("_error_type", "java.lang.RuntimeException", "_error_message", "Boom"));
|
||||||
|
assertThat(stackTrace).startsWith(
|
||||||
|
"java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"
|
||||||
|
.formatted());
|
||||||
assertThat(json).contains(
|
assertThat(json).contains(
|
||||||
"""
|
"java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException"
|
||||||
message\\n\\njava.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.GraylogExtendedLogFormatStructuredLogFormatterTests.shouldFormatException""");
|
.formatted()
|
||||||
|
.replace("\n", "\\n")
|
||||||
|
.replace("\r", "\\r"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -80,12 +80,13 @@ class LogstashStructuredLogFormatterTests extends AbstractStructuredLoggingTests
|
||||||
Map<String, Object> deserialized = deserialize(json);
|
Map<String, Object> deserialized = deserialize(json);
|
||||||
String stackTrace = (String) deserialized.get("stack_trace");
|
String stackTrace = (String) deserialized.get("stack_trace");
|
||||||
assertThat(stackTrace).startsWith(
|
assertThat(stackTrace).startsWith(
|
||||||
"""
|
"java.lang.RuntimeException: Boom%n\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException"
|
||||||
java.lang.RuntimeException: Boom
|
.formatted());
|
||||||
\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException""");
|
|
||||||
assertThat(json).contains(
|
assertThat(json).contains(
|
||||||
"""
|
"java.lang.RuntimeException: Boom%n\\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException"
|
||||||
java.lang.RuntimeException: Boom\\n\\tat org.springframework.boot.logging.log4j2.LogstashStructuredLogFormatterTests.shouldFormatException""");
|
.formatted()
|
||||||
|
.replace("\n", "\\n")
|
||||||
|
.replace("\r", "\\r"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
||||||
|
|
|
@ -46,7 +46,7 @@ class ExtractorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void stackTraceWhenNoPrinterPrintsUsingLoggingSystem() {
|
void stackTraceWhenNoPrinterPrintsUsingFallback() {
|
||||||
Extractor extractor = new Extractor(null, createConverter());
|
Extractor extractor = new Extractor(null, createConverter());
|
||||||
assertThat(extractor.stackTrace(createEvent())).contains("java.lang.RuntimeException: Boom!");
|
assertThat(extractor.stackTrace(createEvent())).contains("java.lang.RuntimeException: Boom!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1252,23 +1252,14 @@ bom {
|
||||||
releaseNotes("https://github.com/liquibase/liquibase/releases/tag/v{version}")
|
releaseNotes("https://github.com/liquibase/liquibase/releases/tag/v{version}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
library("Log4j2", "2.24.3") {
|
library("Log4j2", "2.25.1") {
|
||||||
prohibit {
|
prohibit {
|
||||||
contains "-alpha"
|
contains "-alpha"
|
||||||
contains "-beta"
|
contains "-beta"
|
||||||
because "we don't want alphas or betas"
|
because "we don't want alphas or betas"
|
||||||
}
|
}
|
||||||
group("org.apache.logging.log4j") {
|
group("org.apache.logging.log4j") {
|
||||||
bom("log4j-bom") {
|
bom("log4j-bom")
|
||||||
permit("biz.aQute.bnd:biz.aQute.bnd.annotation")
|
|
||||||
permit("com.github.spotbugs:spotbugs-annotations")
|
|
||||||
permit("org.apache.logging:logging-parent")
|
|
||||||
permit("org.apache.maven.plugin-tools:maven-plugin-annotations")
|
|
||||||
permit("org.jspecify:jspecify")
|
|
||||||
permit("org.osgi:org.osgi.annotation.bundle")
|
|
||||||
permit("org.osgi:org.osgi.annotation.versioning")
|
|
||||||
permit("org.osgi:osgi.annotation")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
links {
|
links {
|
||||||
site("https://logging.apache.org/log4j")
|
site("https://logging.apache.org/log4j")
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package smoketest.structuredlogging.log4j2;
|
package smoketest.structuredlogging.log4j2;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.apache.logging.log4j.core.impl.ThrowableProxy;
|
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
import org.springframework.boot.logging.structured.StructuredLogFormatter;
|
import org.springframework.boot.logging.structured.StructuredLogFormatter;
|
||||||
|
@ -39,9 +41,11 @@ public class CustomStructuredLogFormatter implements StructuredLogFormatter<LogE
|
||||||
result.append(" pid=").append(this.pid);
|
result.append(" pid=").append(this.pid);
|
||||||
}
|
}
|
||||||
result.append(" msg=\"").append(event.getMessage().getFormattedMessage()).append('"');
|
result.append(" msg=\"").append(event.getMessage().getFormattedMessage()).append('"');
|
||||||
ThrowableProxy throwable = event.getThrownProxy();
|
Throwable throwable = event.getThrown();
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
result.append(" error=\"").append(throwable.getExtendedStackTraceAsString()).append('"');
|
StringWriter stackTrace = new StringWriter();
|
||||||
|
throwable.printStackTrace(new PrintWriter(stackTrace));
|
||||||
|
result.append(" error=\"").append(stackTrace).append('"');
|
||||||
}
|
}
|
||||||
result.append('\n');
|
result.append('\n');
|
||||||
return result.toString();
|
return result.toString();
|
||||||
|
|
Loading…
Reference in New Issue