Properties in a log statement are shoved in to message in JsonEncoder #1035
-
|
Hi! I'm using a 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 |
Beta Was this translation helpful? Give feedback.
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.
Instead of the
messageprovider, you can use thepatternprovider with#tryJson{...}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
JsonProviderimplementation that optimizes it. For example, if you know a specific Logger always logs messages in proper JSON format, then you could do something like this: