Skip to content

Commit

Permalink
fix: Use the configured log level even if the logger has already been…
Browse files Browse the repository at this point in the history
… initialized (#190)

Fixes #187

Our own Railtie code makes calls to `logger` which might be run before a user's custom `Judoscale.configure` block. We need to allow configuring the log level at any time.
  • Loading branch information
adamlogic authored Dec 8, 2023
1 parent 609d2e8 commit 7908eb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion judoscale-ruby/lib/judoscale/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions judoscale-ruby/test/logger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7908eb2

Please sign in to comment.