My requirement is to exclude non JSON lines from the file. Data comes into the log file are mainly json and the third-party libraries sometimes emit non-JSON single and multiline logs. JSON logs are single line only.
When used exact string in regex like exclude_lines: ['Resolving eureka endpoints','Fetching config from server','Located environment'] the lines starting with these words are getting excluded. If regex ( ['^[^({).*].*'] ) is used then all lines including JSON are skipped.
It is difficult to put exact phrases to skip, as many of these logs are coming from third-party dependency libraries.
Seen the questions in the forum about how to exclude lines based on regex. But couldn't figure out.
Beat version : 6.6.0 ; OS : Centos 7
Thanks in advance.
Hmmm, that's quite odd. Would you mind posting a few sample lines from your logs, showing a mix of JSON and non-JSON log lines? Please remember to redact any sensitive information.
My log file contains the following data. Only the first few lines are shown here. The pattern is the same all lines. All lines including JSON are single line.
I have tried the regex testers online ( https://regex101.com/ ) with other pattern ^[^{]* It is working as we need.
But when placed as it is like exclude_lines: ^[^{]* skipping all the lines.
Sorry for posting other domain links here.
Thanks. I just tested with the samples you provided and was able to get only JSON logs to be indexed. That is, I was able to get non-JSON logs to be excluded.
I got confused by the double negative and had originally made the wrong suggestion. The correct setting you want is this:
Tried your suggestioninclude_lines: ['^{'] . Also removed the exclude lines. Now also all lines are skipped. The index is not getting created in elasticsearch. The following is the log of filebeat. It seems whenever it encounters non json value it is printing the error.
2019-02-14T18:02:46.133+0530 INFO log/harvester.go:254 Harvester started for file: /logs/test/b1.json
2019-02-14T18:02:46.133+0530 ERROR json/json.go:51 Error decoding JSON: invalid character 'R' looking for beginning of value
2019-02-14T18:02:46.133+0530 ERROR json/json.go:51 Error decoding JSON: invalid character 'F' looking for beginning of value
2019-02-14T18:02:46.136+0530 ERROR json/json.go:51 Error decoding JSON: invalid character 'L' looking for beginning of value
2019-02-14T18:02:46.138+0530 ERROR json/json.go:51 Error decoding JSON: invalid character 'R' looking for beginning of value
2019-02-14T18:02:46.143+0530 ERROR json/json.go:51 Error decoding JSON: invalid character 'R' looking for beginning of value
2019-02-14T18:02:46.145+0530 ERROR json/json.go:51 Error decoding JSON: invalid character 'F' looking for beginning of value
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.