Module: LogStash::Config::Mixin
- Included in:
- LogStash::Codecs::Base, Filters::Base, Inputs::Base, Outputs::Base
- Defined in:
- lib/logstash/config/mixin.rb
Overview
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" => ...
Defined Under Namespace
Modules: DSL
Constant Summary collapse
- CONFIGSORT =
{ Symbol => 0, String => 0, Regexp => 100, }
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#original_params ⇒ Object
Returns the value of attribute original_params.
Class Method Summary collapse
-
.included(base) ⇒ Object
This method is called when someone does ‘include LogStash::Config’.
Instance Method Summary collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
32 33 34 |
# File 'lib/logstash/config/mixin.rb', line 32 def config @config end |
#original_params ⇒ Object
Returns the value of attribute original_params.
33 34 35 |
# File 'lib/logstash/config/mixin.rb', line 33 def original_params @original_params end |
Class Method Details
Instance Method Details
#config_init(params) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 |