JsonContextFieldWriter

class JsonContextFieldWriter : MdcEntryWriter(source)

Writes logging context fields as JSON when using logstash-logback-encoder. This allows you to include object fields in the logging context and have them be included as actual JSON in the log output, instead of as an escaped string.

To use it, configure logback.xml under src/main/resources as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<!-- Writes object values from logging context as actual JSON (not escaped) -->
<mdcEntryWriter class="dev.hermannm.devlog.output.logback.JsonContextFieldWriter"/>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

This requires that you have added ch.qos.logback:logback-classic and net.logstash.logback:logstash-logback-encoder as dependencies.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun writeMdcEntry(generator: JsonGenerator, fieldName: String, mdcKey: String, value: String): Boolean