logback.xml配置
1.输出到控制台logstash结构
2.输出到文件logstash结构
3.输出到redis,logstash接入
<configuration scan="true" scanPeriod="60 seconds">
<appender name="stash" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
</encoder>
</appender>
<appender name="stashfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
logstash/logstash-%d{yyyy-MM-dd}.log
</fileNamePattern>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
</encoder>
</appender>
<appender name="LOGSTASH" class="com.cwbase.logback.RedisAppender">
<source>logstashdemo</source>
<type>dev</type>
<host>127.0.0.1</host>
<port>6379</port>
<key>logstash</key>
<tags>dev</tags>
<mdc>true</mdc>
<location>true</location>
<callerStackIndex>0</callerStackIndex>
</appender>
<root level="debug">
<appender-ref ref="stash" />
<appender-ref ref="stashfile" />
<appender-ref ref="LOGSTASH" />
</root>
</configuration>
依赖
<dependency>
<groupId>com.cwbase</groupId>
<artifactId>logback-redis-appender</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.6</version>
</dependency>