How to Write Formatter Plugin
require 'fluent/plugin/formatter'
module Fluent::Plugin
class MyCSVFormatter < Formatter
# Register MyCSVFormatter as 'my_csv'.
Fluent::Plugin.register_formatter('my_csv', self)
config_param :csv_fields, :array, value_type: :string
# This method does further processing. Configuration parameters can be
# accessed either via `conf` hash or member variables.
def configure(conf)
super
end
# This is the method that formats the data output.
def format(tag, time, record)
values = []
# Look up each required field and collect them from the record
@csv_fields.each do |field|
v = record[field]
unless v
log.error "#{field} is missing."
end
values << v.to_s
end
# Output by joining the fields with a comma
values.join(',')
end
end
endHow To Use Formatters From Plugins
Methods
#format(tag, time, record)
#format(tag, time, record)Writing Tests
Overview of Tests
Last updated
Was this helpful?