Skip to content

Log a warning when the JSON parsing fails #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

magnusbaeck
Copy link
Contributor

This mirrors what the json codec already does. Fixes #21.

@@ -53,7 +53,8 @@ def encode(event)
# from_json_parse uses the Event#from_json method to deserialize and directly produce events
def from_json_parse(json, &block)
LogStash::Event.from_json(json).each { |event| yield event }
rescue LogStash::Json::ParserError
rescue LogStash::Json::ParserError => e
@logger.error("JSON parse error, original data now in message field", :error => e, :data => json)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this condition is automatically recovered by Logstash, I don't think logging it as an error is the right choice. Maybe info? or warn?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I'll stick to a warning since that matches the default log level. Hiding what should be obvious signs of trouble behind a --verbose invocation seems ill-advised.

This mirrors what the json codec already does.
@magnusbaeck magnusbaeck changed the title Log an error when the JSON parsing fails Log a warning when the JSON parsing fails Jun 30, 2016
@magnusbaeck
Copy link
Contributor Author

Updated according to your suggestion @jordansissel. Please have another look.

@jordansissel
Copy link
Contributor

LGTM

@elasticsearch-bot
Copy link

Jordan Sissel merged this into the following branches!

Branch Commits
master e789f4f

@magnusbaeck magnusbaeck deleted the log-parse-errors branch March 24, 2019 19:35
jsvd pushed a commit to jsvd/logstash-codec-json_lines that referenced this pull request Nov 20, 2019
This mirrors what the json codec already does.

Fixes logstash-plugins#25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants