lockback 生成json 日志配置
Posted rigidwang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lockback 生成json 日志配置相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="60 seconds"> <jmxConfigurator/> <property name="appName" value="microarch-sys-service"/> <property name="charset" value="utf-8"/> <contextName>${appName}</contextName> <!--日志输出规则 --> <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>logs/${appName}_%d{yy-MM-dd}</fileNamePattern> <maxHistory>7</maxHistory> </rollingPolicy> <encoder> <pattern> [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n </pattern> <charset>${charset}</charset> </encoder> </appender> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern> [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n </pattern> <charset>${charset}</charset> </encoder> <!--<filter class="ch.qos.logback.classic.filter.ThresholdFilter">--> <!--<level>info</level>--> <!--</filter>--> </appender> <appender name="logstash" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>logs/${appName}_%d{yy-MM-dd}.json</fileNamePattern> <maxHistory>7</maxHistory> </rollingPolicy> <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <providers> <timestamp> <timeZone>UTC</timeZone> </timestamp> <pattern> <pattern> { "ip": "${ip}", "app": "${appName}", "level": "%level", "thread": "%thread", "logger": "%logger{36}", "message": "%msg" } </pattern> </pattern> </providers> </encoder> </appender> <!--日志过滤规则 --> <root level="info"> <appender-ref ref="file"/> <appender-ref ref="console"/> <appender-ref ref="logstash" /> </root> <logger level="info" name="com.cnbmtech.aspect.WebAspect"/> <logger level="info" name="com.cnbmtech.dao"/> <logger level="info" name="com.cnbmtech.aspect.LogDBAspect"/> <!--<logger name="org.hibernate.SQL" level="DEBUG" />--> <logger name="org.hibernate.SQL" level="info"/> <logger level="off" name="org.springframework.cloud.config.client.ConfigServicePropertySourceLocator"/> </configuration>
以上是关于lockback 生成json 日志配置的主要内容,如果未能解决你的问题,请参考以下文章