I am adding some context info to log records using MDC:
MDC.put("Correlation-ID", UUID.randomUUID().toString());
I am using following logback encoder:
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSSX</timestampFormat>
<timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>
<appendLineSeparator>true</appendLineSeparator>
<jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
<prettyPrint>false</prettyPrint>
</jsonFormatter>
</layout>
</encoder>
I've got following log:
{"timestamp":"2020-01-20T11:40:09.850Z","level":"INFO","thread":"main","mdc":{"Correlation-ID":"66f7843c-9855-450d-ad97-b1c78404f051"},"logger":"liquibase.Liquibase"...
I would like to remove root mdc tag to get:
{"timestamp":"2020-01-20T11:40:09.850Z","level":"INFO","thread":"main","Correlation-ID":"66f7843c-9855-450d-ad97-b1c78404f051","logger":"liquibase.Liquibase"...
How would I achive this?
pattern="%d{ISO8601} %-5p - %-26.26c{1} - %notEmpty{[username=%X{username}] - }%m\n"
. I think logback might have something similar? – Mesozoic