lib/fluent/mixin/plaintextformatter.rb in fluent-mixin-plaintextformatter-0.2.3 vs lib/fluent/mixin/plaintextformatter.rb in fluent-mixin-plaintextformatter-0.2.4
- old
+ new
@@ -6,10 +6,12 @@
module PlainTextFormatter
attr_accessor :output_include_time, :output_include_tag, :output_data_type
attr_accessor :add_newline, :field_separator
attr_accessor :remove_prefix, :default_tag
+ attr_accessor :suppress_log_broken_string
+
attr_accessor :f_separator
def first_value(*args)
args.reduce{|a,b| (not a.nil?) ? a : b}
end
@@ -63,10 +65,16 @@
elsif @output_data_type =~ /^attr:(.+)$/
$1.split(',').map(&:strip).reject(&:empty?)
else
raise Fluent::ConfigError, "invalid output_data_type:'#{@output_data_type}'"
end
+
+ @suppress_log_broken_string = first_value(
+ Fluent::Config.bool_value(conf['suppress_log_broken_string']),
+ @suppress_log_broken_string,
+ false
+ )
end
def stringify_record(record)
if @custom_attributes.nil?
case @output_data_type
@@ -103,14 +111,18 @@
begin
time_str + tag_str + stringify_record(record) + (@add_newline ? "\n" : '')
rescue JSON::GeneratorError => e
# partial character in source, but hit end
# source sequence is illegal/malformed utf-8
- $log.error e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
+ unless @suppress_log_broken_string
+ $log.warn e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
+ end
''
rescue ArgumentError => e
raise unless e.message == 'invalid byte sequence in UTF-8'
- $log.error e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
+ unless @suppress_log_broken_string
+ $log.warn e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
+ end
''
end
end
end
end