一.pom.xml配置
dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.3</version>
</dependency>
二.logback-spring.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="true">
<contextName>center-sky</contextName>
<property name="log.path" value="logs" />
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!-- 这是是logstash服务器地址 端口-->
<destination>192.168.33.88:7788</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<providers>
<timestamp/>
<version/>
<message/>
<loggerName/>
<threadName/>
<logLevel/>
<callerData/>
</providers>
</encoder>
</appender>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/logback.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console" />
<appender-ref ref="stash"/>
<appender-ref ref="file" />
</root>
</configuration>
三.logstash-sample.conf配置
input {
tcp {
mode => "server"
host => "192.168.33.88"
port => 7788
codec => json_lines
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
}
output {
elasticsearch {
hosts => ["192.168.33.88:9200"]
action=>"index"
index => "log-%{+YYYY.MM.dd}"
}
stdout{
codec => json_lines
}
}
四.创建索引模式
评论区