Logstash配置文件處理日志時間


將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}"
  }
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM