前言
logstash 使用的是最新的2.3版本,此模板僅爲參考,一切以官方文檔爲準
https://www.elastic.co/guide/en/logstash
input模塊
接收log4j類型日誌
input {
log4j {
type => "log4j-json"
port=>12201
}
}
filter模塊
深入json化message內容
filter{
json {
source => "message"
}
}
output模塊
輸出到es
output {
stdout{codec => rubydebug }
elasticsearch { hosts => ["sz-a-qhfaxes01-es-hw.qhfax.com"]
index => "dev-qhfaxweb-master-logs-%{+YYYY.MM.dd}"
document_type => "%{class}"
}
}
%{class}:class爲消息源中json的key值,使用%{}模板可以將變化的key帶入logstash模板中,使_type的值爲數據class的值。