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
Methods included from Util::Loggable
included, #logger, #slow_logger
Constructor Details
#initialize(params = nil) ⇒ Plugin
Returns a new instance of Plugin.
      49 50 51 52 53 54 55 56 57 58 59 60 61  | 
    
      # File 'lib/logstash/plugin.rb', line 49 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.
      13 14 15  | 
    
      # File 'lib/logstash/plugin.rb', line 13 def execution_context @execution_context end  | 
  
#params ⇒ Object
Returns the value of attribute params.
      13 14 15  | 
    
      # File 'lib/logstash/plugin.rb', line 13 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.
      139 140 141  | 
    
      # File 'lib/logstash/plugin.rb', line 139 def self.lookup(type, name) LogStash::PLUGIN_REGISTRY.lookup_pipeline_plugin(type, name) end  | 
  
.reloadable? ⇒ Boolean
      105 106 107  | 
    
      # File 'lib/logstash/plugin.rb', line 105 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.)
      82 83 84  | 
    
      # File 'lib/logstash/plugin.rb', line 82 def close # .. end  | 
  
#config_name ⇒ String
return the configured name of this plugin
      130 131 132  | 
    
      # File 'lib/logstash/plugin.rb', line 130 def config_name self.class.config_name end  | 
  
#debug_info ⇒ Object
      109 110 111  | 
    
      # File 'lib/logstash/plugin.rb', line 109 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
      75 76 77 78  | 
    
      # File 'lib/logstash/plugin.rb', line 75 def do_close @logger.debug("closing", :plugin => self.class.name) close end  | 
  
#eql?(other) ⇒ Boolean
      45 46 47  | 
    
      # File 'lib/logstash/plugin.rb', line 45 def eql?(other) self.class.name == other.class.name && @params == other.params end  | 
  
#hash ⇒ Object
      40 41 42 43  | 
    
      # File 'lib/logstash/plugin.rb', line 40 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
      69 70 71  | 
    
      # File 'lib/logstash/plugin.rb', line 69 def id @params["id"] end  | 
  
#inspect ⇒ Object
      90 91 92 93 94 95 96 97 98 99  | 
    
      # File 'lib/logstash/plugin.rb', line 90 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
      117 118 119 120 121 122 123 124 125 126  | 
    
      # File 'lib/logstash/plugin.rb', line 117 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
      113 114 115  | 
    
      # File 'lib/logstash/plugin.rb', line 113 def metric=(new_metric) @metric = new_metric end  | 
  
#reloadable? ⇒ Boolean
      101 102 103  | 
    
      # File 'lib/logstash/plugin.rb', line 101 def reloadable? self.class.reloadable? end  | 
  
#to_s ⇒ Object
      86 87 88  | 
    
      # File 'lib/logstash/plugin.rb', line 86 def to_s return "#{self.class.name}: #{@params}" end  |