diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-04-12 18:29:04 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-04-12 18:29:04 -0700 |
commit | f84217267a2282600b2fa2f9e8794753586d5b00 (patch) | |
tree | 27a0072679d2bf6db854ab98dad0117cb33b89be /lib/ohai/hints.rb | |
parent | 654b24f436fde12eb05e8d3725cd27c7c78e5d48 (diff) | |
download | ohai-f84217267a2282600b2fa2f9e8794753586d5b00.tar.gz |
Add debug logging when looking for hints
Diffstat (limited to 'lib/ohai/hints.rb')
-rw-r--r-- | lib/ohai/hints.rb | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/ohai/hints.rb b/lib/ohai/hints.rb index 20420856..a4d18adc 100644 --- a/lib/ohai/hints.rb +++ b/lib/ohai/hints.rb @@ -22,28 +22,32 @@ require "ffi_yajl" module Ohai module Hints def self.refresh_hints - @hints = Hash.new + @hints = {} + end + + def self.parse_hint_file(filename) + begin + json_parser = FFI_Yajl::Parser.new + hash = json_parser.parse(File.read(filename)) + hash || {} # hint + # should exist because the file did, even if it didn't + # contain anything + rescue FFI_Yajl::ParseError => e + Ohai::Log.error("Plugin #{self.name}: Could not parse hint file at #{filename}: #{e.message}") + end end def self.hint?(name) - @hints ||= Hash.new + @hints ||= {} return @hints[name] if @hints[name] - Ohai.config[:hints_path].each do |path| filename = File.join(path, "#{name}.json") - if File.exist?(filename) - begin - json_parser = FFI_Yajl::Parser.new - hash = json_parser.parse(File.read(filename)) - @hints[name] = hash || Hash.new # hint - # should exist because the file did, even if it didn't - # contain anything - rescue FFI_Yajl::ParseError => e - Ohai::Log.error("Could not parse hint file at #{filename}: #{e.message}") - end - end + next unless File.exist?(filename) + Ohai::Log.debug("Found hint #{name}.json at #{filename}") + @hints[name] = parse_hint_file(filename) end + Ohai::Log.debug("Did not find hint #{name}.json in the hint path(s): #{Ohai.config[:hints_path].join(',')} ") unless @hints.key?(name) @hints[name] end end |