Module: Fluent::TextFormatter

Defined in:
lib/fluent/formatter.rb

Defined Under Namespace

Modules: HandleTagAndTimeMixin, StructuredFormatMixin Classes: CsvFormatter, HashFormatter, JSONFormatter, LabeledTSVFormatter, MessagePackFormatter, OutFileFormatter, ProcWrappedFormatter, SingleValueFormatter, StdoutFormatter

Constant Summary collapse

TEMPLATE_REGISTRY =
Registry.new(:formatter_type, 'fluent/plugin/formatter_')

Class Method Summary collapse

Class Method Details

.create(conf) ⇒ Object

Keep backward-compatibility



276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/fluent/formatter.rb', line 276

def self.create(conf)
  format = conf['format']
  if format.nil?
    raise ConfigError, "'format' parameter is required"
  end

  formatter = lookup(format)
  if formatter.respond_to?(:configure)
    formatter.configure(conf)
  end
  formatter
end

.lookup(format) ⇒ Object



271
272
273
# File 'lib/fluent/formatter.rb', line 271

def self.lookup(format)
  TEMPLATE_REGISTRY.lookup(format).call
end

.register_template(name, factory_or_proc) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
# File 'lib/fluent/formatter.rb', line 259

def self.register_template(name, factory_or_proc)
  factory = if factory_or_proc.is_a?(Class) # XXXFormatter
              Proc.new { factory_or_proc.new }
            elsif factory_or_proc.arity == 3 # Proc.new { |tag, time, record| }
              Proc.new { ProcWrappedFormatter.new(factory_or_proc) }
            else # Proc.new { XXXFormatter.new }
              factory_or_proc
            end

  TEMPLATE_REGISTRY.register(name, factory)
end