LOGBACK:如何以自定义JSON格式编写日志

时间:2019-09-04 06:52:15

标签: json spring-boot logback appender

我们有一个spring boot项目,在其中我使用了下附加程序以JSON格式编写日志。

    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
        <layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
            <jsonFormatter
                class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
                <prettyPrint>true</prettyPrint>
            </jsonFormatter>
            <timestampFormat>yyyy-MM-dd' 'HH:mm:ss.SSS</timestampFormat>
        </layout>
    </encoder>

但是现在我想在JSON对象结构中添加更多属性以及时间戳,级别等。

此外,我还想在JSON日志中添加标头。

那么实现这一目标的最佳方法是什么。优选地,我只想使用logback类来执行此操作,但是我看不到与标头有关的方法。那么,有哪些可用于自定义JSON格式的替代选项。

0 个答案:

没有答案
相关问题