项目日志格式化
1、项目logback-spring.xm修改
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> |
|---|
2、filebeat配置文件修改 目录:/data/filebeat
|
# Each - is a prospector. Most options can be set at the prospector level, so - input_type: log # Paths that should be crawled and fetched. Glob based paths.
# Exclude lines. A list of regular expressions to match. It drops the lines that are # Include lines. A list of regular expressions to match. It exports the lines that are # Exclude files. A list of regular expressions to match. Filebeat drops the files that # Optional additional fields. These field can be freely picked ### Multiline options # Mutiline can be used for log messages spanning multiple lines. This is common # The regexp Pattern that has to be matched. The example pattern matches all lines starting with [ # Defines if the pattern set under pattern should be negated or not. Default is false. # Match can be set to "after" or "before". It is used to define if lines should be append to a pattern |
|---|
启动命令 nohup ./filebeat -e -c xxx.yml > /dev/null 2>&1 &
3.logstash 配置文件修改(添加filter)
|
filter { if [type] == "mapi-app-forum-error" { json { source => "message" target => "jsoncontent" remove_field => ["message"] } }
if [type] == "web-forum-error" { json { source => "message" target => "jsoncontent" remove_field => ["message"] } } } |
|---|
sudo bash
启动命令 nohup ./logstash -f ./xxx.conf > ./xxx.log 2>&1 &
4.logstash 嵌套json日志类型转换配置 (中括号隔开)
|
if [type] == "web-forum-info" { } |
|---|
5.logstash 嵌套json日志删除多余字段(中括号隔开)
|
json { source => "message" target => "jsoncontent" remove_field => [ "message","[jsoncontent][source]","[jsoncontent][input_type]","[jsoncontent][type]","[jsoncontent][offset]"] } |
|---|

浙公网安备 33010602011771号