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

Fixed the issue with log level on the chef config #14294

Merged
merged 3 commits into from
Mar 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions knife/lib/chef/knife.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,20 @@ def config_source(key)
def apply_computed_config
Chef::Config[:color] = config[:color]

case Chef::Config[:verbosity]
when 0, nil
Chef::Config[:log_level] = :warn
when 1
Chef::Config[:log_level] = :info
when 2
Chef::Config[:log_level] = :debug
else
Chef::Config[:log_level] = :trace
end
# If the verbosity is not set, use what is already present on the log_level config.
Chef::Config[:log_level] = case Chef::Config[:verbosity]
when 0
:warn
when 1
:info
when 2
:debug
when nil
# The default log_level is auto and that is not a valid log_level.
Chef::Config[:log_level] == :auto ? :warn : Chef::Config[:log_level]
else
:trace
end

Chef::Config[:log_level] = :trace if ENV["KNIFE_DEBUG"]

Expand Down
3 changes: 3 additions & 0 deletions knife/spec/unit/knife_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ class AwesomeCheffsCommand < Chef::ChefFS::Knife
end

it "sets the default log_level to warn so we can issue Chef::Log.warn" do
# Reset the log level to the default value
Chef::Config[:log_level] = :auto

knife_command = KnifeSpecs::TestYourself.new([])
knife_command.configure_chef
expect(Chef::Config[:log_level]).to eql(:warn)
Expand Down