<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>