Properties in a log statement are shoved in to message in JsonEncoder #1035
Unanswered
mityakoval
asked this question in
Q&A
Replies: 1 comment
-
Instead of the <pattern>
{
"msg": "#tryJson{%message}"
}
</pattern> Note that this will add a lot of overhead to your logging, since it tries to format every message as JSON (and if it fails, it falls back to logging it as a string) If high performance is a requirement, you could write your own custom public class MyJsonProvider extends AbstractJsonProvider<ILoggingEvent> {
@Override
public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException {
generator.writeFieldName("msg");
if ("my.logger.that.writes.in.json".equals(event.getLoggerName())
&& event.getFormattedMessage().startsWith("{")) {
generator.writeRaw(event.getFormattedMessage());
} else {
generator.writeString(event.getFormattedMessage());
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I'm using a
net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder
and usually all the properties I add to my log statements are nicely displayed. One of the library's internal logs also seem to be in a JSON format but it's just getting formatted in to a string and shoved into themessage
property which is really hard to read.Is there a way to instruct Logback to recognise the JSON logged by the library and merge according to the existing encoder config?
Here's the
logback.xml
:Beta Was this translation helpful? Give feedback.
All reactions