logstash结合es,日志收集

时间:2021-10-21 23:26:11

1.下载好logstash后,解压目录

 

2.进入bin目录,新建文件 logstash_default.conf

input {
        tcp {
                port => 4560
                codec => "json_lines"
        }
}
#json_lines
output {

                stdout {
                        codec => rubydebug
                }
         elasticsearch {hosts => "127.0.0.1:9200"} }

 

3.我使用的是logback日志,在日志xml文件添加配置如下

 <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>127.0.0.1:4560</destination>
        <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
            <customFields>{"appname":"my-service"}</customFields>
        </encoder>
    </appender>

 

4.启动项目,然后到es里查询下日志数据