Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make better use of freeze #3170

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/fluent/plugin/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/formatter_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin/formatter_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/fluent/plugin/formatter_ltsv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/fluent/plugin/formatter_out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/formatter_single_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/formatter_tsv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down