module Fluent::PluginHelper::Formatter
Attributes
_formatters[R]
Public Class Methods
included(mod)
click to toggle source
# File lib/fluent/plugin_helper/formatter.rb, line 70 def self.included(mod) mod.include FormatterParams end
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 76 def initialize super @_formatters_started = false @_formatters = {} # usage => formatter end
Public Instance Methods
after_shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 129 def after_shutdown formatter_operate(:after_shutdown) super end
before_shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 119 def before_shutdown formatter_operate(:before_shutdown) super end
close()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 134 def close formatter_operate(:close) super end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 82 def configure(conf) super @formatter_configs.each do |section| if @_formatters[section.usage] raise Fluent::ConfigError, "duplicated formatter configured: #{section.usage}" end formatter = Plugin.new_formatter(section[:@type], parent: self) formatter.configure(section.corresponding_config_element) @_formatters[section.usage] = formatter end end
formatter_create(usage: '', type: nil, conf: nil, default_type: nil)
click to toggle source
# File lib/fluent/plugin_helper/formatter.rb, line 25 def formatter_create(usage: '', type: nil, conf: nil, default_type: nil) formatter = @_formatters[usage] return formatter if formatter && !type && !conf type = if type type elsif conf && conf.respond_to?(:[]) raise Fluent::ConfigError, "@type is required in <format>" unless conf['@type'] conf['@type'] elsif default_type default_type else raise ArgumentError, "BUG: both type and conf are not specified" end formatter = Fluent::Plugin.new_formatter(type, parent: self) config = case conf when Fluent::Config::Element conf when Hash # in code, programmer may use symbols as keys, but Element needs strings conf = Hash[conf.map{|k,v| [k.to_s, v]}] Fluent::Config::Element.new('format', usage, conf, []) when nil Fluent::Config::Element.new('format', usage, {}, []) else raise ArgumentError, "BUG: conf must be a Element, Hash (or unspecified), but '#{conf.class}'" end formatter.configure(config) if @_formatters_started formatter.start end @_formatters[usage] = formatter formatter end
formatter_operate(method_name, &block)
click to toggle source
# File lib/fluent/plugin_helper/formatter.rb, line 103 def formatter_operate(method_name, &block) @_formatters.each_pair do |usage, formatter| begin formatter.__send__(method_name) block.call(formatter) if block_given? rescue => e log.error "unexpected error while #{method_name}", usage: usage, formatter: formatter, error: e end end end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 124 def shutdown formatter_operate(:shutdown) super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 95 def start super @_formatters_started = true @_formatters.each_pair do |usage, formatter| formatter.start end end
stop()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 114 def stop super formatter_operate(:stop) end
terminate()
click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/formatter.rb, line 139 def terminate formatter_operate(:terminate) @_formatters_started = false @_formatters = {} super end