Json logging: exception in message #54250
|
Is there a way to get the exception stack into the top level message field? Like a normal non json log stacktrace print? |
Replies: 3 comments 5 replies
|
@xstefank do you know? You have been looking into JSON logging not so long ago. |
|
Hi @agreedSkiing, this will be possible in Quarkus 3.36.0 with the But we cannot override the already supplied JSON keys because Generator directly writes to the stream. So, you need to exclude the existing "message" and provided a different name of your new key. Hopefully, this works for you. |
|
To add a ready-to-use implementation of the Implement import io.quarkus.logging.json.runtime.JsonProvider;
import jakarta.json.stream.JsonGenerator;
import org.jboss.logmanager.ExtLogRecord;
import java.io.PrintWriter;
import java.io.StringWriter;
public class StackTraceInMessageProvider implements JsonProvider {
@Override
public void writeTo(JsonGenerator generator, ExtLogRecord record) {
String message = record.getFormattedMessage();
Throwable thrown = record.getThrown();
if (thrown != null) {
StringWriter sw = new StringWriter();
thrown.printStackTrace(new PrintWriter(sw));
message = message + "
" + sw;
}
generator.write("message", message);
}
@Override
public boolean isDefault() {
return true; // replaces the default "message" field
}
}Register via ServiceLoader — create the file: With the content: This merges the full stacktrace into the |
To add a ready-to-use implementation of the
JsonProviderSPI that @xstefank mentioned (Quarkus 3.36+):Implement
JsonProviderto merge the stacktrace into themessagefield: