Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the configured log level even if the logger has already been initialized #190

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading