將SpringBoot生成的日志文件,通過Logstash傳輸到Elasticsearch。日志文件內容格式如下
2019-11-12 22:01:23.358 調用==>用戶退出登錄接口參數=>"{\"phone\":\"17010058888\",\"token\":\"oo:8da500acb09d7e3ef2e9e61dcc6b5908\"}"
編寫logstash.conf文件,內容如下,將日志打印的時間戳轉換為timestamp類型
input { file { type => "auth_log" path => ["/logs/auth.log"] start_position => "beginning" sincedb_path => "/dev/null" } } filter { grok { match => { "message" => "\s*%{TIMESTAMP_ISO8601:time}\s*%{NOTSPACE:rest}" } } date { match => ["time", "yyyy-MM-dd HH:mm:ss.SSS"] target => "@timestamp" } mutate { remove_field =>["message"] } } output { elasticsearch { hosts => "ip:9200" index => "logstash-%{+YYYY.MM.dd}" } }