Class: Fluent::TextFormatter::CsvFormatter

Inherits:
Formatter
  • Object
show all
Includes:
HandleTagAndTimeMixin
Defined in:
lib/fluent/formatter.rb

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Method Summary collapse

Methods included from HandleTagAndTimeMixin

#configure, #filter_record, included

Methods inherited from Formatter

#configure

Methods included from Configurable

#config, #configure, included, lookup_type, register_type

Constructor Details

#initializeCsvFormatter

Returns a new instance of CsvFormatter.



205
206
207
208
# File 'lib/fluent/formatter.rb', line 205

def initialize
  super
  require 'csv'
end

Instance Method Details

#format(tag, time, record) ⇒ Object



210
211
212
213
214
215
216
217
218
# File 'lib/fluent/formatter.rb', line 210

def format(tag, time, record)
  filter_record(tag, time, record)
  row = @fields.inject([]) do |memo, key|
      memo << record[key]
      memo
  end
  CSV.generate_line(row, col_sep: @delimiter,
                    force_quotes: @force_quotes)
end