Skip to content

Commit

Permalink
Ensure plugin config marked :deprecated logs to deprecation logger (#…
Browse files Browse the repository at this point in the history
…16833)

Previously when the `:deprecated` modifier was used in the plugin config DSL a
log message was sent at `:warn` level to the main logger. This commit updates
that message to be routed *only* to the deprecation logger.
  • Loading branch information
donoghuc authored Jan 6, 2025
1 parent e2b322e commit 274c212
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
14 changes: 7 additions & 7 deletions logstash-core/lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ def config_init(params)
if opts && opts[:deprecated]
extra = opts[:deprecated].is_a?(String) ? opts[:deprecated] : ""
extra.gsub!("%PLUGIN%", self.class.config_name)
self.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)
self.deprecation_logger.deprecated("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.", {})

end

Expand Down
27 changes: 13 additions & 14 deletions logstash-core/spec/logstash/config/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,28 @@
describe LogStash::Config::Mixin do
context "when encountering a deprecated option" do
let(:password) { "sekret" }
let(:double_logger) { double("logger").as_null_object }

subject do
let(:deprecation_logger) { double("DeprecationLogger").as_null_object }
let(:plugin_class) do
Class.new(LogStash::Filters::Base) do
include LogStash::Config::Mixin
config_name "test_deprecated"
milestone 1
config :old_opt, :validate => :string, :deprecated => "this is old school"
config :password, :validate => :password
end.new({
"old_opt" => "whut",
"password" => password
})
end
end

it "should not log the password" do
expect(LogStash::Logging::Logger).to receive(:new).with(anything).and_return(double_logger)
expect(double_logger).to receive(:warn) do |arg1, arg2|
message = 'You are using a deprecated config setting "old_opt" set in test_deprecated. Deprecated settings will continue to work, but are scheduled for removal from logstash in the future. this is old school If you have any questions about this, please visit the #logstash channel on freenode irc.'
expect(arg1).to eq(message)
expect(arg2[:plugin].to_s).to include('"password"=><password>')
end.once
subject
instance = plugin_class.new("old_opt" => "whut", "password" => password)
allow(instance).to receive(:deprecation_logger).and_return(deprecation_logger)

expect(deprecation_logger).to receive(:deprecated) do |message, _|
expect(message).to include("old_opt")
expect(message).to include("this is old school")
expect(message).not_to include(password)
end

instance.send(:config_init, instance.params)
end
end

Expand Down

0 comments on commit 274c212

Please sign in to comment.