为了能够更好的在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>