lockback 生成json 日誌配置
阿新 • • 發佈:2018-12-13
<?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>