Class: Fluent::Plugin::JSONFormatter

Inherits:
Formatter show all
Defined in:
lib/fluent/plugin/formatter_json.rb

Direct Known Subclasses

Compat::TextFormatter::JSONFormatter

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Method Summary collapse

Methods included from OwnedByMixin

#log, #owner, #owner=

Methods inherited from Base

#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #initialize, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, included, #initialize, lookup_type, register_type

Constructor Details

This class inherits a constructor from Fluent::Plugin::Base

Instance Method Details

#configure(conf) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fluent/plugin/formatter_json.rb', line 26

def configure(conf)
  super

  begin
    raise LoadError unless @json_parser == 'oj'
    require 'oj'
    Oj.default_options = {mode: :compat}
    @dump_proc = Oj.method(:dump)
  rescue LoadError
    @dump_proc = Yajl.method(:dump)
  end
end

#format(tag, time, record) ⇒ Object



39
40
41
# File 'lib/fluent/plugin/formatter_json.rb', line 39

def format(tag, time, record)
  "#{@dump_proc.call(record)}\n"
end