Skip to content

Commit

Permalink
Merge pull request #14294 from chef/CHEF-652-knife-log-level
Browse files Browse the repository at this point in the history
Fixed the issue with log level on the chef config
  • Loading branch information
johnmccrae committed Mar 27, 2024
2 parents 8d71b49 + a4af7e6 commit 5e5fe79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
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

0 comments on commit 5e5fe79

Please sign in to comment.