其他分享
首页 > 其他分享> > 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>

 

标签:log,reqid,method,json,uid,message,logback,日志,springboot
来源: https://www.cnblogs.com/wujf/p/16478003.html