Skip to content

Commit 90d1ab4

Browse files
committed
Log a warning when the JSON parsing fails.
This mirrors what the json codec already does.
1 parent 443750f commit 90d1ab4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/logstash/codecs/json_lines.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def encode(event)
5353
# from_json_parse uses the Event#from_json method to deserialize and directly produce events
5454
def from_json_parse(json, &block)
5555
LogStash::Event.from_json(json).each { |event| yield event }
56-
rescue LogStash::Json::ParserError
56+
rescue LogStash::Json::ParserError => e
57+
@logger.warn("JSON parse error, original data now in message field", :error => e, :data => json)
5758
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
5859
end
5960

@@ -62,7 +63,8 @@ def legacy_parse(json, &block)
6263
# ignore empty/blank lines which LogStash::Json#load returns as nil
6364
o = LogStash::Json.load(json)
6465
yield(LogStash::Event.new(o)) if o
65-
rescue LogStash::Json::ParserError
66+
rescue LogStash::Json::ParserError => e
67+
@logger.warn("JSON parse error, original data now in message field", :error => e, :data => json)
6668
yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
6769
end
6870

0 commit comments

Comments
 (0)