diff --git a/lib/fluent/plugin/formatter.rb b/lib/fluent/plugin/formatter.rb index 9fc874d648..b524f40ecd 100644 --- a/lib/fluent/plugin/formatter.rb +++ b/lib/fluent/plugin/formatter.rb @@ -63,9 +63,9 @@ def configure(conf) super @newline = case newline when :lf - "\n" + "\n".freeze when :crlf - "\r\n" + "\r\n".freeze end end end diff --git a/lib/fluent/plugin/formatter_csv.rb b/lib/fluent/plugin/formatter_csv.rb index 100bcbff6b..74760a1df7 100644 --- a/lib/fluent/plugin/formatter_csv.rb +++ b/lib/fluent/plugin/formatter_csv.rb @@ -27,7 +27,7 @@ class CsvFormatter < Formatter helpers :record_accessor config_param :delimiter, default: ',' do |val| - ['\t', 'TAB'].include?(val) ? "\t" : val + ['\t', 'TAB'].include?(val) ? "\t".freeze : val.freeze end config_param :force_quotes, :bool, default: true # "array" looks good for type of :fields, but this implementation removes tailing comma diff --git a/lib/fluent/plugin/formatter_hash.rb b/lib/fluent/plugin/formatter_hash.rb index d91e78995f..9b66ca15af 100644 --- a/lib/fluent/plugin/formatter_hash.rb +++ b/lib/fluent/plugin/formatter_hash.rb @@ -27,7 +27,7 @@ class HashFormatter < Formatter def format(tag, time, record) line = record.to_s - line << @newline.freeze if @add_newline + line << @newline if @add_newline line end end diff --git a/lib/fluent/plugin/formatter_ltsv.rb b/lib/fluent/plugin/formatter_ltsv.rb index eb87f98e0d..cbcab8b5e6 100644 --- a/lib/fluent/plugin/formatter_ltsv.rb +++ b/lib/fluent/plugin/formatter_ltsv.rb @@ -25,8 +25,8 @@ class LabeledTSVFormatter < Formatter # http://ltsv.org/ - config_param :delimiter, :string, default: "\t" - config_param :label_delimiter, :string, default: ":" + config_param :delimiter, :string, default: "\t".freeze + config_param :label_delimiter, :string, default: ":".freeze config_param :add_newline, :bool, default: true # TODO: escaping for \t in values @@ -36,7 +36,7 @@ def format(tag, time, record) formatted << @delimiter if formatted.length.nonzero? formatted << "#{label}#{@label_delimiter}#{value}" end - formatted << @newline.freeze if @add_newline + formatted << @newline if @add_newline formatted end end diff --git a/lib/fluent/plugin/formatter_out_file.rb b/lib/fluent/plugin/formatter_out_file.rb index 98c4126ce2..364303000a 100644 --- a/lib/fluent/plugin/formatter_out_file.rb +++ b/lib/fluent/plugin/formatter_out_file.rb @@ -29,9 +29,9 @@ class OutFileFormatter < Formatter config_param :output_tag, :bool, default: true config_param :delimiter, default: "\t" do |val| case val - when /SPACE/i then ' ' - when /COMMA/i then ',' - else "\t" + when /SPACE/i then ' '.freeze + when /COMMA/i then ','.freeze + else "\t".freeze end end config_set_default :time_type, :string diff --git a/lib/fluent/plugin/formatter_single_value.rb b/lib/fluent/plugin/formatter_single_value.rb index 569ded8479..ed28236da8 100644 --- a/lib/fluent/plugin/formatter_single_value.rb +++ b/lib/fluent/plugin/formatter_single_value.rb @@ -23,12 +23,12 @@ class SingleValueFormatter < Formatter Plugin.register_formatter('single_value', self) - config_param :message_key, :string, default: 'message' + config_param :message_key, :string, default: 'message'.freeze config_param :add_newline, :bool, default: true def format(tag, time, record) text = record[@message_key].to_s.dup - text << @newline.freeze if @add_newline + text << @newline if @add_newline text end end diff --git a/lib/fluent/plugin/formatter_tsv.rb b/lib/fluent/plugin/formatter_tsv.rb index df14c662cd..5b4df2dfe7 100644 --- a/lib/fluent/plugin/formatter_tsv.rb +++ b/lib/fluent/plugin/formatter_tsv.rb @@ -26,13 +26,13 @@ class TSVFormatter < Formatter desc 'Field names included in each lines' config_param :keys, :array, value_type: :string desc 'The delimiter character (or string) of TSV values' - config_param :delimiter, :string, default: "\t" + config_param :delimiter, :string, default: "\t".freeze desc 'The parameter to enable writing to new lines' config_param :add_newline, :bool, default: true def format(tag, time, record) formatted = @keys.map{|k| record[k].to_s }.join(@delimiter) - formatted << @newline.freeze if @add_newline + formatted << @newline if @add_newline formatted end end