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)

METRICS_REGISTRY
OUTPUT_REGISTRY
PARSER_REGISTRY
REGISTRIES
SD_REGISTRY
SEARCH_PATHS
STORAGE_REGISTRY

Public Class Methods

add_plugin_dir(dir) click to toggle source
# File lib/fluent/plugin.rb, line 102
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 91
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 121
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 117
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 150
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 167
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.extend FeatureAvailabilityChecker
  impl
end
new_input(type) click to toggle source
# File lib/fluent/plugin.rb, line 109
def self.new_input(type)
  new_impl('input', INPUT_REGISTRY, type)
end
new_metrics(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 129
def self.new_metrics(type, parent: nil)
  new_impl('metrics', METRICS_REGISTRY, type, parent)
end
new_output(type) click to toggle source
# File lib/fluent/plugin.rb, line 113
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 138
def self.new_parser(type, parent: nil)
  if type[0] == '/' && type[-1] == '/'
    # This usage is not recommended for new API... create RegexpParser directly
    require 'fluent/parser'
    impl = Fluent::TextParser.lookup(type)
    impl.extend FeatureAvailabilityChecker
    impl
  else
    new_impl('parser', PARSER_REGISTRY, type, parent)
  end
end
new_sd(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 125
def self.new_sd(type, parent: nil)
  new_impl('sd', SD_REGISTRY, type, parent)
end
Also aliased as: new_service_discovery
new_service_discovery(type, parent: nil)

This should be defined for fluent-plugin-config-formatter type arguments.

Alias for: new_sd
new_storage(type, parent: nil) click to toggle source
# File lib/fluent/plugin.rb, line 154
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 55
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 51
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 77
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 158
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 43
def self.register_input(type, klass)
  register_impl('input', INPUT_REGISTRY, type, klass)
end
register_metrics(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 63
def self.register_metrics(type, klass)
  register_impl('metrics', METRICS_REGISTRY, type, klass)
end
register_output(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 47
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 67
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_sd(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 59
def self.register_sd(type, klass)
  register_impl('sd', SD_REGISTRY, type, klass)
end
register_storage(type, klass) click to toggle source
# File lib/fluent/plugin.rb, line 87
def self.register_storage(type, klass)
  register_impl('storage', STORAGE_REGISTRY, type, klass)
end