module LogStash::Config::Mixin
This module is meant as a mixin to classes wishing to be configurable from config files
The idea is that you can do this:
class Foo < LogStash::Config
# Add config file settings config "path" => ... config "tag" => ... # Add global flags (becomes --foo-bar) flag "bar" => ...
end
And the config file should let you do:
foo {
"path" => ... "tag" => ...
}
Constants
- CONFIGSORT
Attributes
config[RW]
original_params[RW]
Public Class Methods
included(base)
click to toggle source
This method is called when someone does 'include LogStash::Config'
# File lib/logstash/config/mixin.rb, line 42 def self.included(base) # Add the DSL methods to the 'base' given. base.extend(LogStash::Config::Mixin::DSL) end
Public Instance Methods
config_init(params)
click to toggle source
# File lib/logstash/config/mixin.rb, line 47 def config_init(params) # Validation will modify the values inside params if necessary. # For example: converting a string to a number, etc. # Keep a copy of the original config params so that we can later # differentiate between explicit configuration and implicit (default) # configuration. @original_params = params.clone # store the plugin type, turns LogStash::Inputs::Base into 'input' @plugin_type = self.class.ancestors.find { |a| a.name =~ /::Base$/ }.config_name # warn about deprecated variable use params.each do |name, value| opts = self.class.get_config[name] if opts && opts[:deprecated] extra = opts[:deprecated].is_a?(String) ? opts[:deprecated] : "" extra.gsub!("%PLUGIN%", self.class.config_name) @logger.warn("You are using a deprecated config setting " + "#{name.inspect} set in #{self.class.config_name}. " + "Deprecated settings will continue to work, " + "but are scheduled for removal from logstash " + "in the future. #{extra} If you have any questions " + "about this, please visit the #logstash channel " + "on freenode irc.", :name => name, :plugin => self) end end # Set defaults from 'config :foo, :default => somevalue' self.class.get_config.each do |name, opts| next if params.include?(name.to_s) if opts.include?(:default) and (name.is_a?(Symbol) or name.is_a?(String)) # default values should be cloned if possible # cloning prevents case opts[:default] when FalseClass, TrueClass, NilClass, Numeric params[name.to_s] = opts[:default] else params[name.to_s] = opts[:default].clone end end # Allow plugins to override default values of config settings if self.class.default?(name) params[name.to_s] = self.class.get_default(name) end end if !self.class.validate(params) raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_settings") end # set instance variables like '@foo' for each config value given. params.each do |key, value| next if key[0, 1] == "@" # Set this key as an instance variable only if it doesn't start with an '@' @logger.debug("config #{self.class.name}/@#{key} = #{value.inspect}") instance_variable_set("@#{key}", value) end @config = params end