Class: Fluent::Plugin::JSONFormatter

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

Direct Known Subclasses

Compat::TextFormatter::JSONFormatter

Constant Summary

Constants included from Newline::Mixin

Newline::Mixin::DEFAULT_NEWLINE

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Constants inherited from Formatter

Formatter::PARSER_TYPES

Instance Attribute Summary

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, #initialize, lookup_type, register_type

Methods inherited from Formatter

#formatter_type

Methods included from TimeMixin::Formatter

included, #time_formatter_create

Methods included from OwnedByMixin

#log, #owner, #owner=

Methods inherited from Base

#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #initialize, #inspect, #multi_workers_ready?, #plugin_root_dir, #reloadable_plugin?, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Instance Method Details

#configure(conf) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/formatter_json.rb', line 30

def configure(conf)
  super

  if @json_parser == 'oj'
    if Fluent::OjOptions.available?
      @dump_proc = Oj.method(:dump)
    else
      log.info "Oj isn't installed, fallback to Yajl as json parser"
      @dump_proc = Yajl.method(:dump)
    end
  else
    @dump_proc = Yajl.method(:dump)
  end

  # format json is used on various highload environment, so re-define method to skip if check
  unless @add_newline
    define_singleton_method(:format, method(:format_without_nl))
  end
end

#format(tag, time, record) ⇒ Object



50
51
52
# File 'lib/fluent/plugin/formatter_json.rb', line 50

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

#format_without_nl(tag, time, record) ⇒ Object



54
55
56
# File 'lib/fluent/plugin/formatter_json.rb', line 54

def format_without_nl(tag, time, record)
  @dump_proc.call(record)
end