Class: LogStash::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/plugin.rb

Constant Summary collapse

NL =
"\n"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = nil) ⇒ Plugin

Returns a new instance of Plugin.



27
28
29
30
31
# File 'lib/logstash/plugin.rb', line 27

def initialize(params=nil)
  @params = LogStash::Util.deep_clone(params)
  @logger = Cabin::Channel.get(LogStash)
  @metric_plugin = LogStash::Instrument::NullMetric.new
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/logstash/plugin.rb', line 11

def logger
  @logger
end

#paramsObject

Returns the value of attribute params.



10
11
12
# File 'lib/logstash/plugin.rb', line 10

def params
  @params
end

Class Method Details

.lookup(type, name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/logstash/plugin.rb', line 79

def self.lookup(type, name)
  path = "logstash/#{type}s/#{name}"

  # first check if plugin already exists in namespace and continue to next step if not
  begin
    return namespace_lookup(type, name)
  rescue NameError
    logger.debug("Plugin not defined in namespace, checking for plugin file", :type => type, :name => name, :path => path)
  end

  # try to load the plugin file. ex.: lookup("filter", "grok") will require logstash/filters/grok
  require(path)

  # check again if plugin is now defined in namespace after the require
  namespace_lookup(type, name)
rescue LoadError, NameError => e
  raise(LogStash::PluginLoadingError, I18n.t("logstash.pipeline.plugin-loading-error", :type => type, :name => name, :path => path, :error => e.to_s))
end

Instance Method Details

#closeObject



44
45
46
# File 'lib/logstash/plugin.rb', line 44

def close
  # ..
end

#debug_infoObject



73
74
75
# File 'lib/logstash/plugin.rb', line 73

def debug_info
  [self.class.to_s, original_params]
end

#do_closeObject



36
37
38
39
# File 'lib/logstash/plugin.rb', line 36

def do_close
  @logger.debug("closing", :plugin => self.class.name)
  close
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/logstash/plugin.rb', line 22

def eql?(other)
  self.class.name == other.class.name && @params == other.params
end

#hashObject



16
17
18
19
# File 'lib/logstash/plugin.rb', line 16

def hash
  params.hash ^
  self.class.name.hash
end

#inspectObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/logstash/plugin.rb', line 61

def inspect
  if !@params.nil?
    description = @params
      .reject { |k, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) }
      .collect { |k, v| "#{k}=>#{v.inspect}" }
    return "<#{self.class.name} #{description.join(", ")}>"
  else
    return "<#{self.class.name} --->"
  end
end

#metricObject

This is a shim to make sure that plugin that record metric still work with 2.4

github.com/elastic/logstash/issues/5539



56
57
58
# File 'lib/logstash/plugin.rb', line 56

def metric
  @metric_plugin
end

#to_sObject



48
49
50
# File 'lib/logstash/plugin.rb', line 48

def to_s
  return "#{self.class.name}: #{@params}"
end