我开始kibana
,elastiksearch
和logstash
我写了简单的服务器:
@Slf4j
@RestController
public class TestController {
@GetMapping(value = "/test")
public String test(){
log.debug("test");
return "OK";
}
}
添加追加器:
<appender name="STASH" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>test.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>redditApp.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
当我启动服务器时-使用JSON类型的日志创建test.log
文件。
当我打电话给/test
时-在test.log
中添加以下行:
{"@timestamp":"2018-08-07T14:36:08.624+03:00","@version":"1","message":"test","logger_name":"com.example.logs.controllers.TestController","thread_name":"http-nio-8080-exec-1","level":"DEBUG","level_value":10000}
之后,我想通过logstash解析此文件,并将所有日志添加到elasticksearch。我在logstash中添加了confik:
input {
file {
path => "D:\projects\logs\*.log"
codec => "json"
type => "logback"
}
}
output {
if [type]=="logback" {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "logback-%{+YYYY.MM.dd}"
}
}
}
并启动logstash。它开始成功。
此后,我打开了kibana,我不明白如何查看日志。
答案 0 :(得分:0)
[type]
已过时。从输出中将其删除:
output {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "logback-%{+YYYY.MM.dd}"
}
}
编辑:和您的输入。实际上,请尝试使用标签:
input {
file {
path => "D:\projects\logs\*.log"
codec => "json"
tags => ["logback"]
}
}
output {
if "logback" in tags {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "logback-%{+YYYY.MM.dd}"
}
}
}