summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-04-12 18:29:04 -0700
committerTim Smith <tsmith84@gmail.com>2016-04-12 18:29:04 -0700
commitf84217267a2282600b2fa2f9e8794753586d5b00 (patch)
tree27a0072679d2bf6db854ab98dad0117cb33b89be
parent654b24f436fde12eb05e8d3725cd27c7c78e5d48 (diff)
downloadohai-f84217267a2282600b2fa2f9e8794753586d5b00.tar.gz
Add debug logging when looking for hints
-rw-r--r--lib/ohai/hints.rb32
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