lib/fluent/plugin/out_scribe.rb in fluent-plugin-scribe-0.10.13 vs lib/fluent/plugin/out_scribe.rb in fluent-plugin-scribe-0.10.14

- old
+ new

@@ -24,10 +24,11 @@ config_param :field_ref, :string, :default => 'message' config_param :timeout, :integer, :default => 30 config_param :remove_prefix, :string, :default => nil config_param :add_newline, :bool, :default => false + config_param :ignore_invalid_record, :bool, :default => false config_param :default_category, :string, :default => 'unknown' config_param :format_to_json, :bool, :default => false unless method_defined?(:log) define_method(:log) { $log } @@ -90,10 +91,21 @@ next unless @format_to_json || record.has_key?(@field_ref) message = @format_to_json ? record : record[@field_ref] if message.kind_of?(Array) or message.kind_of?(Hash) - message = message.to_json + begin + message = message.to_json + rescue => e + if @ignore_invalid_record + # This warning can be disabled by 'log_level error' + log.warn "got invalid message", message: message, error: e, error_class: e.class + next + else + # Keep existence behaviour + raise + end + end end if @add_newline message = message + "\n" end