diff --git a/lib/fluent/plugin/formatter_hash.rb b/lib/fluent/plugin/formatter_hash.rb index f0afb5d08a..d91e78995f 100644 --- a/lib/fluent/plugin/formatter_hash.rb +++ b/lib/fluent/plugin/formatter_hash.rb @@ -19,20 +19,11 @@ module Fluent module Plugin class HashFormatter < Formatter + include Fluent::Plugin::Newline::Mixin + Plugin.register_formatter('hash', self) config_param :add_newline, :bool, default: true - config_param :newline, :enum, list: [:lf, :crlf], default: :lf - - def configure(conf) - super - @newline = case newline - when :lf - "\n" - when :crlf - "\r\n" - end - end def format(tag, time, record) line = record.to_s diff --git a/lib/fluent/plugin/formatter_json.rb b/lib/fluent/plugin/formatter_json.rb index 435f233245..180d23eeca 100644 --- a/lib/fluent/plugin/formatter_json.rb +++ b/lib/fluent/plugin/formatter_json.rb @@ -20,11 +20,12 @@ module Fluent module Plugin class JSONFormatter < Formatter + include Fluent::Plugin::Newline::Mixin + Plugin.register_formatter('json', self) config_param :json_parser, :string, default: 'oj' config_param :add_newline, :bool, default: true - config_param :newline, :enum, list: [:lf, :crlf], default: :lf def configure(conf) super @@ -42,13 +43,6 @@ def configure(conf) unless @add_newline define_singleton_method(:format, method(:format_without_nl)) end - - @newline = case newline - when :lf - "\n" - when :crlf - "\r\n" - end end def format(tag, time, record) diff --git a/lib/fluent/plugin/formatter_ltsv.rb b/lib/fluent/plugin/formatter_ltsv.rb index 1181b9760b..eb87f98e0d 100644 --- a/lib/fluent/plugin/formatter_ltsv.rb +++ b/lib/fluent/plugin/formatter_ltsv.rb @@ -19,6 +19,8 @@ module Fluent module Plugin class LabeledTSVFormatter < Formatter + include Fluent::Plugin::Newline::Mixin + Plugin.register_formatter('ltsv', self) # http://ltsv.org/ @@ -26,18 +28,6 @@ class LabeledTSVFormatter < Formatter config_param :delimiter, :string, default: "\t" config_param :label_delimiter, :string, default: ":" config_param :add_newline, :bool, default: true - config_param :newline, :enum, list: [:lf, :crlf], default: :lf - - def configure(conf) - super - - @newline = case newline - when :lf - "\n" - when :crlf - "\r\n" - end - end # TODO: escaping for \t in values def format(tag, time, record) diff --git a/lib/fluent/plugin/formatter_out_file.rb b/lib/fluent/plugin/formatter_out_file.rb index f392225b3e..98c4126ce2 100644 --- a/lib/fluent/plugin/formatter_out_file.rb +++ b/lib/fluent/plugin/formatter_out_file.rb @@ -21,6 +21,8 @@ module Fluent module Plugin class OutFileFormatter < Formatter + include Fluent::Plugin::Newline::Mixin + Plugin.register_formatter('out_file', self) config_param :output_time, :bool, default: true @@ -32,20 +34,12 @@ class OutFileFormatter < Formatter else "\t" end end - config_param :newline, :enum, list: [:lf, :crlf], default: :lf config_set_default :time_type, :string config_set_default :time_format, nil # time_format nil => iso8601 def configure(conf) super @timef = time_formatter_create - - @newline = case newline - when :lf - "\n" - when :crlf - "\r\n" - end end def format(tag, time, record) diff --git a/lib/fluent/plugin/formatter_single_value.rb b/lib/fluent/plugin/formatter_single_value.rb index 3aa51e53b9..569ded8479 100644 --- a/lib/fluent/plugin/formatter_single_value.rb +++ b/lib/fluent/plugin/formatter_single_value.rb @@ -19,22 +19,12 @@ module Fluent module Plugin class SingleValueFormatter < Formatter + include Fluent::Plugin::Newline::Mixin + Plugin.register_formatter('single_value', self) config_param :message_key, :string, default: 'message' config_param :add_newline, :bool, default: true - config_param :newline, :enum, list: [:lf, :crlf], default: :lf - - def configure(conf) - super - - @newline = case newline - when :lf - "\n" - when :crlf - "\r\n" - end - end def format(tag, time, record) text = record[@message_key].to_s.dup diff --git a/lib/fluent/plugin/formatter_tsv.rb b/lib/fluent/plugin/formatter_tsv.rb index e366af50a3..df14c662cd 100644 --- a/lib/fluent/plugin/formatter_tsv.rb +++ b/lib/fluent/plugin/formatter_tsv.rb @@ -19,6 +19,8 @@ module Fluent module Plugin class TSVFormatter < Formatter + include Fluent::Plugin::Newline::Mixin + Plugin.register_formatter('tsv', self) desc 'Field names included in each lines' @@ -27,19 +29,6 @@ class TSVFormatter < Formatter config_param :delimiter, :string, default: "\t" desc 'The parameter to enable writing to new lines' config_param :add_newline, :bool, default: true - desc 'The newline code' - config_param :newline, :enum, list: [:lf, :crlf], default: :lf - - def configure(conf) - super - - @newline = case newline - when :lf - "\n" - when :crlf - "\r\n" - end - end def format(tag, time, record) formatted = @keys.map{|k| record[k].to_s }.join(@delimiter)