Java教程

springboot输出json日志

本文主要是介绍springboot输出json日志,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>6.6</version>
        </dependency>

 

<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/app.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- 按天回滚 daily -->
            <fileNamePattern>${log.path}/bak.%d{yyyy-MM-dd}.log
            </fileNamePattern>
            <!-- 日志最大的历史 60天 -->
            <maxHistory>60</maxHistory>
        </rollingPolicy>
        <!-- <encoder> <pattern>${log.pattern}</pattern> </encoder> -->
        <encoder charset="UTF-8"
            class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <pattern>
                    <pattern>
                        {
                        "reqid": "%X{reqid}",
                        "uid": "%X{uid}",
                        "time": "%date{yyyy-MM-dd HH:mm:ss.SSS}",
                        "level": "%level",
                        "pid": "${PID:-}",
                        "class": "%logger",
                        "method":"%method",
                        "line":"%line",
                        "message":"%message"
                        }
                    </pattern>
                </pattern>
            </providers>
        </encoder>
    </appender>

 

这篇关于springboot输出json日志的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!