Class: LogStash::Plugin
- Inherits:
-
Object
- Object
- LogStash::Plugin
- Includes:
- Config::Mixin, Util::Loggable
- Defined in:
- lib/logstash/plugin.rb
Direct Known Subclasses
Constant Summary collapse
- NL =
"\n"
Constants included from Config::Mixin
Config::Mixin::PLUGIN_VERSION_0_9_0, Config::Mixin::PLUGIN_VERSION_1_0_0
Constants included from Util::SubstitutionVariables
Util::SubstitutionVariables::SUBSTITUTION_PLACEHOLDER_REGEX
Instance Attribute Summary collapse
-
#execution_context ⇒ Object
Returns the value of attribute execution_context.
-
#params ⇒ Object
Returns the value of attribute params.
Attributes included from Config::Mixin
Class Method Summary collapse
-
.lookup(type, name) ⇒ Object
This is keep for backward compatibility, the logic was moved into the registry class but some plugins use this method to return a specific instance on lookup.
- .reloadable? ⇒ Boolean
Instance Method Summary collapse
-
#close ⇒ Object
Subclasses should implement this close method if you need to perform any special tasks during shutdown (like flushing, etc.).
-
#config_name ⇒ String
return the configured name of this plugin.
- #debug_info ⇒ Object
-
#do_close ⇒ Object
close is called during shutdown, after the plugin worker main task terminates.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#id ⇒ String
Return a uniq ID for this plugin configuration, by default we will generate a UUID.
-
#initialize(params = nil) ⇒ Plugin
constructor
A new instance of Plugin.
- #inspect ⇒ Object
- #metric ⇒ Object
- #metric=(new_metric) ⇒ Object
- #reloadable? ⇒ Boolean
- #to_s ⇒ Object
Methods included from Config::Mixin
Methods included from Util::SubstitutionVariables
#deep_replace, #replace_placeholders
Constructor Details
#initialize(params = nil) ⇒ Plugin
Returns a new instance of Plugin.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/logstash/plugin.rb', line 45 def initialize(params=nil) @logger = self.logger # need to access settings statically because plugins are initialized in config_ast with no context. settings = LogStash::SETTINGS @slow_logger = self.slow_logger(settings.get("slowlog.threshold.warn"), settings.get("slowlog.threshold.info"), settings.get("slowlog.threshold.debug"), settings.get("slowlog.threshold.trace")) @params = LogStash::Util.deep_clone(params) # The id should always be defined normally, but in tests that might not be the case # In the future we may make this more strict in the Plugin API @params["id"] ||= "#{self.class.config_name}_#{SecureRandom.uuid}" end |
Instance Attribute Details
#execution_context ⇒ Object
Returns the value of attribute execution_context.
9 10 11 |
# File 'lib/logstash/plugin.rb', line 9 def execution_context @execution_context end |
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/logstash/plugin.rb', line 9 def params @params end |
Class Method Details
.lookup(type, name) ⇒ Object
This is keep for backward compatibility, the logic was moved into the registry class but some plugins use this method to return a specific instance on lookup
Should I remove this now and make sure the pipeline invoke the Registry or I should wait for 6.0 Its not really part of the public api but its used by the tests a lot to mock the plugins.
135 136 137 138 |
# File 'lib/logstash/plugin.rb', line 135 def self.lookup(type, name) require "logstash/plugins/registry" LogStash::PLUGIN_REGISTRY.lookup_pipeline_plugin(type, name) end |
.reloadable? ⇒ Boolean
101 102 103 |
# File 'lib/logstash/plugin.rb', line 101 def self.reloadable? true end |
Instance Method Details
#close ⇒ Object
Subclasses should implement this close method if you need to perform any special tasks during shutdown (like flushing, etc.)
78 79 80 |
# File 'lib/logstash/plugin.rb', line 78 def close # .. end |
#config_name ⇒ String
return the configured name of this plugin
126 127 128 |
# File 'lib/logstash/plugin.rb', line 126 def config_name self.class.config_name end |
#debug_info ⇒ Object
105 106 107 |
# File 'lib/logstash/plugin.rb', line 105 def debug_info [self.class.to_s, original_params] end |
#do_close ⇒ Object
close is called during shutdown, after the plugin worker main task terminates
71 72 73 74 |
# File 'lib/logstash/plugin.rb', line 71 def do_close @logger.debug("Closing", :plugin => self.class.name) close end |
#eql?(other) ⇒ Boolean
41 42 43 |
# File 'lib/logstash/plugin.rb', line 41 def eql?(other) self.class.name == other.class.name && @params == other.params end |
#hash ⇒ Object
36 37 38 39 |
# File 'lib/logstash/plugin.rb', line 36 def hash params.hash ^ self.class.name.hash end |
#id ⇒ String
Return a uniq ID for this plugin configuration, by default we will generate a UUID
If the user defines a ‘id => ’ABC’‘ in the configuration we will return
65 66 67 |
# File 'lib/logstash/plugin.rb', line 65 def id @params["id"] end |
#inspect ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/logstash/plugin.rb', line 86 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 |
#metric ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/logstash/plugin.rb', line 113 def metric # We can disable metric per plugin if we want in the configuration # we will use the NullMetric in this case. @metric_plugin ||= if @enable_metric # Fallback when testing plugin and no metric collector are correctly configured. @metric.nil? ? LogStash::Instrument::NamespacedNullMetric.new : @metric else LogStash::Instrument::NamespacedNullMetric.new(@metric, :null) end end |
#metric=(new_metric) ⇒ Object
109 110 111 |
# File 'lib/logstash/plugin.rb', line 109 def metric=(new_metric) @metric = new_metric end |
#reloadable? ⇒ Boolean
97 98 99 |
# File 'lib/logstash/plugin.rb', line 97 def reloadable? self.class.reloadable? end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/logstash/plugin.rb', line 82 def to_s return "#{self.class.name}: #{@params}" end |