為了能夠更好的在ELK平臺分析日志拆又,所以配置輸出json格式的日志搜囱。
配置maven的依賴
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.7</version>
</dependency>
配置logback.xml
<appender name="LOGSTASH" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<charset>utf8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>D:\home\logs\ssm2logstash-%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>