summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2015-08-06 11:34:57 -0700
committerClaire McQuin <claire@getchef.com>2015-08-06 11:59:57 -0700
commit31d6b0e30659557080dcfd66ec6223aef4fecc1f (patch)
tree1786a46ca9d88f3c4323eb49e17cfecb18d72f66
parent98d4a28f3d8968edd81e878438404fbc009df0a3 (diff)
downloadohai-mcquin/ohai-config/logging.tar.gz
Resolve :auto log levelmcquin/ohai-config/logging
-rw-r--r--lib/ohai/config.rb4
-rw-r--r--lib/ohai/system.rb10
-rw-r--r--spec/unit/system_spec.rb9
3 files changed, 19 insertions, 4 deletions
diff --git a/lib/ohai/config.rb b/lib/ohai/config.rb
index 139912b5..fa0cc8e9 100644
--- a/lib/ohai/config.rb
+++ b/lib/ohai/config.rb
@@ -54,7 +54,7 @@ module Ohai
# (e.g., Ohai::Config[:plugin_path] << some_path) in their config files.
default :disabled_plugins, []
default :hints_path, default_hints_path
- default :log_level, :info
+ default :log_level, :auto
default :log_location, STDERR
default :plugin_path, default_plugin_path
@@ -91,7 +91,7 @@ module Ohai
config_context :ohai do
default :disabled_plugins, []
default :hints_path, Ohai::Config.default_hints_path
- default :log_level, :info
+ default :log_level, :auto
default :log_location, STDERR
default :plugin_path, Ohai::Config.default_plugin_path
end
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index d733191f..6b06e2a8 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -50,6 +50,7 @@ module Ohai
@v6_dependency_solver = Hash.new
configure_ohai
+ configure_logging
@loader = Ohai::Loader.new(self)
@runner = Ohai::Runner.new(self, true)
@@ -213,9 +214,16 @@ module Ohai
!Ohai.config[:plugin_path].include?(Ohai::Config[:directory])
Ohai.config[:plugin_path] << Ohai.config[:directory]
end
+ end
+ def configure_logging
Ohai::Log.init(Ohai.config[:log_location])
- Ohai::Log.level = Ohai.config[:log_level]
+
+ if Ohai.config[:log_level] == :auto
+ Ohai::Log.level = :info
+ else
+ Ohai::Log.level = Ohai.config[:log_level]
+ end
end
end
end
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index 1d6d65f5..e3c0b7b1 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -96,8 +96,15 @@ describe "Ohai::System" do
end
it 'configures logging' do
+ log_level = :debug
+ Ohai.config[:log_level] = log_level
expect(Ohai::Log).to receive(:init).with(Ohai.config[:log_location])
- expect(Ohai::Log).to receive(:level=).with(Ohai.config[:log_level])
+ expect(Ohai::Log).to receive(:level=).with(log_level)
+ Ohai::System.new
+ end
+
+ it 'resolves log_level when set to :auto' do
+ expect(Ohai::Log).to receive(:level=).with(:info)
Ohai::System.new
end
end