logstash-plugins / logstash-codec-json

Apache License 2.0
23 stars 29 forks source link

Refactor: reduce parse error logging level #39

Open kares opened 2 years ago

kares commented 2 years ago

before https://github.com/logstash-plugins/logstash-codec-json/pull/37 there were 2 error handlers:

  rescue LogStash::Json::ParserError => e
    @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => json)
    yield LogStash::Event.new("message" => json, "tags" => ["_jsonparsefailure"])
  rescue StandardError => e
    # This should NEVER happen. But hubris has been the cause of many pipeline breaking things
    # If something bad should happen we just don't want to crash logstash here.
    @logger.warn(
      "An unexpected error occurred parsing JSON data",
      :data => json,
      :message => e.message,
      :class => e.class.name,
      :backtrace => e.backtrace
    )

... this got replaced (in #37) by a single handler that logs at error level and always generates a fallback event:

  rescue => e
    @logger.error("JSON parse error, original data now in message field", message: e.message, exception: e.class, data: json)
    yield parse_json_error_event(json)

the gist of the change here is to "reduce" the logging on parsing errors to a warn and only log at the error level when smt unexpected happens ...