class Fluent::TextFormatter::CsvFormatter

Public Class Methods

new() click to toggle source
Calls superclass method Fluent::Configurable.new
# File lib/fluent/formatter.rb, line 201
def initialize
  super
  require 'csv'
end

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/formatter.rb, line 206
def configure(conf)
  super
  @fields = fields.select { |f| !f.empty? }
  raise ConfigError, "empty value is specified in fields parameter" if @fields.empty?

  @generate_opts = {col_sep: @delimiter, force_quotes: @force_quotes}
end
format(tag, time, record) click to toggle source
# File lib/fluent/formatter.rb, line 214
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, @generate_opts)
end