-
I'm using a <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<message/>
<loggerName>
<fieldName>loggerName</fieldName>
</loggerName>
<nestedField>
<fieldName>thrown</fieldName>
<providers>
<throwableClassName>
<fieldName>name</fieldName>
</throwableClassName>
<stackTrace>
<fieldName>extendedStackTrace</fieldName>
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
</throwableConverter>
</stackTrace>
</providers>
</nestedField>
</providers>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
And it's producing logs like this: {
"message": "Starting app",
"loggerName": "my.api.App",
"thrown": {}
} I only want the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Dan, There is unfortunately no built-in way to accomplish what you describe. The PatternJsonProvider is the only provider with the ability to omit empty fields (cfr In the meantime you can decorate the Jackson JsonGenerator yourself to make it filter empty fields. The following sample JsonGeneratorDecorator should do the job:
Then simply register the decorator in your logback configuration file as follows:
Note that this will filter all properties and and won't be limited to your "nested" property. Properties with a value satisfying one of the following conditions will be removed (i.e. not included in the final output):
Hope this helps. Do not hesitate to ask for more information if needed. |
Beta Was this translation helpful? Give feedback.
Hi Dan,
There is unfortunately no built-in way to accomplish what you describe. The PatternJsonProvider is the only provider with the ability to omit empty fields (cfr
omitEmptyField
property). We have plan to make this feature available to all providers and are working on it... expect this feature to be included in one of the up coming releases.In the meantime you can decorate the Jackson JsonGenerator yourself to make it filter empty fields. The following sample JsonGeneratorDecorator should do the job: