summaryrefslogtreecommitdiff
path: root/lib/chef/workstation_config_loader.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2014-09-02 16:54:08 -0700
committerdanielsdeleo <dan@getchef.com>2014-09-03 12:44:47 -0700
commitb6f52b35e77e733c627455e368a5dd30bc22daf5 (patch)
tree691e725fc6be13fc37f10cae3c9944548df2449f /lib/chef/workstation_config_loader.rb
parenta261ead4fd60bd909cdaa5a1e22ceec200d42f0b (diff)
downloadchef-b6f52b35e77e733c627455e368a5dd30bc22daf5.tar.gz
Add debug/info logging for knife config file finding
To resolve a chicken/egg issue with the logger being configured *after* the config is located and read, knife will now check for a KNIFE_DEBUG variable and initialize the logger to debug early in the startup process when that variable is set.
Diffstat (limited to 'lib/chef/workstation_config_loader.rb')
-rw-r--r--lib/chef/workstation_config_loader.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/chef/workstation_config_loader.rb b/lib/chef/workstation_config_loader.rb
index c5e26e8acc..6715d4eec2 100644
--- a/lib/chef/workstation_config_loader.rb
+++ b/lib/chef/workstation_config_loader.rb
@@ -18,6 +18,7 @@
require 'chef/config_fetcher'
require 'chef/config'
+require 'chef/null_logger'
class Chef
@@ -26,9 +27,11 @@ class Chef
# Path to a config file requested by user, (e.g., via command line option). Can be nil
attr_reader :explicit_config_file
- def initialize(explicit_config_file)
+ # TODO: initialize this with a logger for Chef and Knife
+ def initialize(explicit_config_file, logger=nil)
@explicit_config_file = explicit_config_file
@config_location = nil
+ @logger = logger || NullLogger.new
end
def no_config_found?
@@ -80,6 +83,16 @@ class Chef
private
+ def have_config?(path)
+ if path_exists?(path)
+ logger.info("Using config at #{path}")
+ true
+ else
+ logger.debug("Config not found at #{path}, trying next option")
+ false
+ end
+ end
+
def locate_local_config
candidate_configs = []
@@ -105,7 +118,7 @@ class Chef
end
candidate_configs.find do | candidate_config |
- path_exists?(candidate_config)
+ have_config?(candidate_config)
end
end
@@ -156,5 +169,9 @@ class Chef
"Relevant file content:\n" + lines.join("\n") + "\n"
end
+ def logger
+ @logger
+ end
+
end
end