Class: Fluent::Plugin::JqFormatter

Inherits:
Formatter
  • Object
show all
Includes:
JqMixin
Defined in:
lib/fluent/plugin/formatter_jq.rb

Constant Summary

Constants included from JqMixin

JqMixin::JqError

Instance Method Summary collapse

Methods included from JqMixin

#configure, included, #jq_transform, #shutdown, #start, #start_process

Constructor Details

#initializeJqFormatter

Returns a new instance of JqFormatter.



32
33
34
# File 'lib/fluent/plugin/formatter_jq.rb', line 32

def initialize
	super
end

Instance Method Details

#format(tag, time, record) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/formatter_jq.rb', line 36

def format(tag, time, record)
	item = jq_transform record
	if item.instance_of?(String)
	  item
	else
	  MultiJson.dump item
	end
rescue JqError
	msg = "Format failed with #{@jq}#{log.on_debug { ' on ' + MultiJson.dump(record) }}, error: #{$!.message}"
	log.error msg
	case @on_error
	when :skip
	  return ''
	when :ignore
	  return MultiJson.dump(record)
	when :raise_error
	  raise msg
	end
end