module Fluent::Plugin

Constants

BUFFER_REGISTRY

feature plugin: second class plugins (instantiated by Plugins or Helpers)

FILTER_REGISTRY
FORMATTER_REGISTRY
INPUT_REGISTRY

first class plugins (instantiated by Engine)

OUTPUT_REGISTRY
PARSER_REGISTRY
REGISTRIES
SEARCH_PATHS
STORAGE_REGISTRY

Public Class Methods

add_plugin_dir(dir) click to toggle source
# File lib/fluent/plugin.rb, line 92
def self.add_plugin_dir(dir)
  REGISTRIES.each do |r|
    r.paths.push(dir)
  end
  nil
end
lookup_type_from_class(klass_or_its_name) click to toggle source
# File lib/fluent/plugin.rb, line 81
def self.lookup_type_from_class(klass_or_its_name)
  klass = if klass_or_its_name.is_a? Class
            klass_or_its_name
          elsif klass_or_its_name.is_a? String
            eval(klass_or_its_name) # const_get can't handle qualified klass name (ex: A::B)
          else
            raise ArgumentError, "invalid argument type #{klass_or_its_name.class}: #{klass_or_its_name}"
          end
  REGISTRIES.reduce(nil){|a, r| a || r.reverse_lookup(klass) }
end
new_buffer(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 111
def self.new_buffer(type, parent: nil)
  new_impl('buffer', BUFFER_REGISTRY, type, parent)
end
new_filter(type) click to toggle source
# File lib/fluent/plugin.rb, line 107
def self.new_filter(type)
  new_impl('filter', FILTER_REGISTRY, type)
end
new_formatter(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 127
def self.new_formatter(type, parent: nil)
  new_impl('formatter', FORMATTER_REGISTRY, type, parent)
end
new_impl(kind, registry, type, parent=nil) click to toggle source
# File lib/fluent/plugin.rb, line 144
def self.new_impl(kind, registry, type, parent=nil)
  # "'type' not found" is handled by registry
  obj = registry.lookup(type)
  impl = case
         when obj.is_a?(Class)
           obj.new
         when obj.respond_to?(:call) && obj.arity == 0
           obj.call
         else
           raise Fluent::ConfigError, "#{kind} plugin '#{type}' is not a Class nor callable (without arguments)."
         end
  if parent && impl.respond_to?("owner=")
    impl.owner = parent
  end
  impl
end
new_input(type) click to toggle source
# File lib/fluent/plugin.rb, line 99
def self.new_input(type)
  new_impl('input', INPUT_REGISTRY, type)
end
new_output(type) click to toggle source
# File lib/fluent/plugin.rb, line 103
def self.new_output(type)
  new_impl('output', OUTPUT_REGISTRY, type)
end
new_parser(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 115
def self.new_parser(type, parent: nil)
  require 'fluent/parser'

  if type[0] == '/' && type[-1] == '/'
    # This usage is not recommended for new API... create RegexpParser directly
    require 'fluent/parser'
    Fluent::TextParser.lookup(type)
  else
    new_impl('parser', PARSER_REGISTRY, type, parent)
  end
end
new_storage(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 131
def self.new_storage(type, parent: nil)
  new_impl('storage', STORAGE_REGISTRY, type, parent)
end
register_buffer(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 53
def self.register_buffer(type, klass)
  register_impl('buffer', BUFFER_REGISTRY, type, klass)
end
register_filter(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 49
def self.register_filter(type, klass)
  register_impl('filter', FILTER_REGISTRY, type, klass)
end
register_formatter(type, klass_or_proc) click to toggle source
# File lib/fluent/plugin.rb, line 67
def self.register_formatter(type, klass_or_proc)
  if klass_or_proc.respond_to?(:call) && klass_or_proc.arity == 3 # Proc.new { |tag, time, record| }
    # This usage is not recommended for new API
    require 'fluent/formatter'
    register_impl('formatter', FORMATTER_REGISTRY, type, Proc.new { Fluent::TextFormatter::ProcWrappedFormatter.new(klass_or_proc) })
  else
    register_impl('formatter', FORMATTER_REGISTRY, type, klass_or_proc)
  end
end
register_impl(kind, registry, type, value) click to toggle source
# File lib/fluent/plugin.rb, line 135
def self.register_impl(kind, registry, type, value)
  if !value.is_a?(Class) && !value.respond_to?(:call)
    raise Fluent::ConfigError, "Invalid implementation as #{kind} plugin: '#{type}'. It must be a Class, or callable."
  end
  registry.register(type, value)
  $log.trace "registered #{kind} plugin '#{type}'" if defined?($log)
  nil
end
register_input(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 41
def self.register_input(type, klass)
  register_impl('input', INPUT_REGISTRY, type, klass)
end
register_output(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 45
def self.register_output(type, klass)
  register_impl('output', OUTPUT_REGISTRY, type, klass)
end
register_parser(type, klass_or_proc) click to toggle source
# File lib/fluent/plugin.rb, line 57
def self.register_parser(type, klass_or_proc)
  if klass_or_proc.is_a?(Regexp)
    # This usage is not recommended for new API
    require 'fluent/parser'
    register_impl('parser', PARSER_REGISTRY, type, Proc.new { Fluent::TextParser::RegexpParser.new(klass_or_proc) })
  else
    register_impl('parser', PARSER_REGISTRY, type, klass_or_proc)
  end
end
register_storage(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 77
def self.register_storage(type, klass)
  register_impl('storage', STORAGE_REGISTRY, type, klass)
end