View on GitHub

json-log-domain

Library supporting JSON-logging with Logback and Stackdriver

Logback support library

Artifact containing base-classes for generated code and some logger configuration.

Note that the DomainMarker (parent for generated classes) can be combined with other markers using and(..), like

logger.info(system("fedora").tags(LINUX).and(Markers.append("my", object)), "Hello world");

MDC-style logging

To enable MDC-style JSON logging for Logback, enable a JsonProvider in the configuration:

<encoder class="net.logstash.logback.encoder.LogstashEncoder">
    <!-- add provider for JSON MDC -->
    <provider class="com.github.skjolber.log.domain.utils.configuration.JsonMdcJsonProvider"/>
</encoder>

This will make sure to include JSON MDC also when doing plain text logging.

Async logger + MDC

As MDC data must be captured before the logging event leaves the thread, so if you are using a multi-threaded approach, like AsyncAppender, make sure to include a call to capture the MDC data like this example.