diff --git a/judoscale-ruby/lib/judoscale/logger.rb b/judoscale-ruby/lib/judoscale/logger.rb index 492a329b..dfc9ea2c 100644 --- a/judoscale-ruby/lib/judoscale/logger.rb +++ b/judoscale-ruby/lib/judoscale/logger.rb @@ -6,7 +6,11 @@ module Judoscale module Logger def logger - @logger ||= LoggerProxy.new(Config.instance.logger, Config.instance.log_level) + if @logger && @logger.log_level == Config.instance.log_level + @logger + else + @logger = LoggerProxy.new(Config.instance.logger, Config.instance.log_level) + end end end diff --git a/judoscale-ruby/test/logger_test.rb b/judoscale-ruby/test/logger_test.rb index 9f739ee9..955483f8 100644 --- a/judoscale-ruby/test/logger_test.rb +++ b/judoscale-ruby/test/logger_test.rb @@ -46,6 +46,15 @@ module Judoscale end end + it "respects the configured log_level even if the logger has been initialized" do + logger.debug "this triggers the logger initialization" + + use_config log_level: :fatal do + logger.public_send method_name, "some message" + _(messages).wont_include "some message" + end + end + it "respects the level set by the original logger when the log level config is not overridden" do original_logger.level = ::Logger::Severity::FATAL