我正在使用MDC为日志记录添加上下文信息:
MDC.put("Correlation-ID", UUID.randomUUID().toString());
我正在使用以下的logback编码器:
<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>
我有以下日志:
{"timestamp":"2020-01-20T11:40:09.850Z","level":"INFO","thread":"main","mdc":{"Correlation-ID":"66f7843c-9855-450d-ad97-b1c78404f051"},"logger":"liquibase.Liquibase"...
我想删除根MDC标记,以得到:
{"timestamp":"2020-01-20T11:40:09.850Z","level":"INFO","thread":"main","Correlation-ID":"66f7843c-9855-450d-ad97-b1c78404f051","logger":"liquibase.Liquibase"...
我该如何实现这个目标?
pattern="%d{ISO8601} %-5p - %-26.26c{1} - %notEmpty{[username=%X{username}] - }%m\n"
。我认为logback可能有类似的功能? - Rob Audenaerde