Method: Fluent::Compat::TextFormatter.register_template

Defined in:
lib/fluent/compat/formatter.rb

.register_template(type, template) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/compat/formatter.rb', line 38

def self.register_template(type, template)
  # TODO: warn when deprecated to use Plugin.register_formatter directly
  if template.is_a?(Class)
    Fluent::Plugin.register_formatter(type, template)
  elsif template.respond_to?(:call) && template.arity == 3 # Proc.new { |tag, time, record| }
    Fluent::Plugin.register_formatter(type, Proc.new { ProcWrappedFormatter.new(template) })
  elsif template.respond_to?(:call)
    Fluent::Plugin.register_formatter(type, template)
  else
    raise ArgumentError, "Template for formatter must be a Class or callable object"
  end
end