Skip to content

Commit 0b48703

Browse files
committed
formatter_csv: use cache only when owner is provided
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 80c02fb commit 0b48703

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/fluent/compat/formatter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ def csv_for_thread
112112
def csv_thread_key
113113
raise NotImplementedError, "Compat CsvFormatter does not support CSV cache. Do not use this method."
114114
end
115+
116+
def csv_cacheable?
117+
false
118+
end
115119
end
116120

117121
class SingleValueFormatter < Fluent::Plugin::SingleValueFormatter

lib/fluent/plugin/formatter_csv.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ class CsvFormatter < Formatter
3535
config_param :fields, :array, value_type: :string
3636
config_param :add_newline, :bool, default: true
3737

38+
def csv_cacheable?
39+
owner ? true : false
40+
end
41+
3842
def csv_thread_key
39-
"#{owner.plugin_id}_csv_formatter_#{@usage}_csv"
43+
csv_cacheable? ? "#{owner.plugin_id}_csv_formatter_#{@usage}_csv" : nil
4044
end
4145

4246
def csv_for_thread
43-
Thread.current[csv_thread_key] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts)
47+
if csv_cacheable?
48+
Thread.current[csv_thread_key] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts)
49+
else
50+
CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts)
51+
end
4452
end
4553

4654
def configure(conf)

0 commit comments

Comments
 (0)