I'm new in using logstash (6.3.2) to parse log data, I want to parse datas in json fmt from logs file to txt files. The steps of input and filter are ok, but there's some problem with output, below is the output section from my code snippet:
output {
if [channel] == "brsdk" {
file {
codec =>
line {
format => "%{bussiness}^^%{channel}^^%{[databody][name]}^^%{[databody][certNo]}^^%{[databody][eventType]}^^%{[databody][customerId]}^^%{[databody][mobile]}^^%{[databody][dataFrom]}"
}
path => "/data/log/logstash/%{+YYYYMM}/brsdk.%{+YYYYMMdd}.txt"
}
}
}
As you see, I parse data to text with JSON filed name mapping, but there's little problem, such as: if in JSON:
{"databody":{"certNo":"0222302X","customerId":663626902,"dataFrom":"baiqishi","eventType":"","name":"Lee"},"channel":"bqssdk","bussiness":"query"}
under the databody
, the eventType
field is empty, the mobile
field is not exist, so in the output text looks like [databody][mobile]
. my problems are:
-
If the field value is empty (
eventType
), how to export to text in form as two single quots:''
; -
If the field not exist (
mobile
), how to export to text in form as two single quots:''
;
I don't know the output codec grammar clearly, and I can't find out some document from offical docs, so how to write in
file {
codec =>
line {}
}
Thanks