class Fluent::Plugin::ProtobufFormatter
ProtobufFormatter
for Fluentd
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/formatter_protobuf.rb, line 78 def configure(conf) super(conf) raise Fluent::ConfigError, "Missing 'include_paths'" if @include_paths.empty? @include_paths.each { |path| require_proto!(path) } unless @include_paths.empty? class_lookup = Google::Protobuf::DescriptorPool.generated_pool.lookup(@class_name) raise Fluent::ConfigError, "class name '#{@class_name}' not found" if class_lookup.nil? @protobuf_class = class_lookup.msgclass end
format(_tag, _time, record)
click to toggle source
# File lib/fluent/plugin/formatter_protobuf.rb, line 95 def format(_tag, _time, record) format_record = @format_field == '' ? record : record[@format_field] protobuf_msg = if @decode_json @protobuf_class.decode_json(Oj.dump(format_record), { ignore_unknown_fields: @ignore_unknown_fields }) else @protobuf_class.new(format_record) end @protobuf_class.encode(protobuf_msg) end
formatter_type()
click to toggle source
# File lib/fluent/plugin/formatter_protobuf.rb, line 91 def formatter_type :binary end
require_proto!(filename)
click to toggle source
# File lib/fluent/plugin/formatter_protobuf.rb, line 107 def require_proto!(filename) Kernel.method(@require_method.to_sym).call(filename) rescue LoadError => e raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.message}" end