summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-02-27 17:49:20 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-02-27 17:49:20 -0800
commitba6eb720ee601d4c150e0a3ebdc8236c990bbcb0 (patch)
treeba426710943977612d81eb21edfc14d78e07ab5d
parent512597d0eaf5a2b83e0997d8074ec1c3a5fab118 (diff)
downloadohai-ba6eb720ee601d4c150e0a3ebdc8236c990bbcb0.tar.gz
fix ohai logger problems.
i believe this gets the logic correct in that we want to configure the logger when we're coming from the command line but want to skip it when we're coming from chef or from other APIs that directly construct an Ohai::System object. i suspect this is what thom was trying to do by moving the Ohai::Log.init call into the Ohai::Application class (which avoids it being called entirely when Chef creates its Ohai::System object) here: https://github.com/chef/ohai/pull/942/files but that change broke the behavior where we were also supposed to skip the rest of the configure_logging method in Ohai::System when run under chef client. I tried going down the route of having the Ohai::Application class construct the Ohai::System object and then having it be the responsibility of that caller to do configure_logging work. However, I suspect that the initializer in Ohai::System does way too much and that the purpose of configuring the logger where it is, is that it must be initialized in the middle of object creation before it goes on and creates the Loader, the Runner, creates Hints and removes constants. So, I went the route of threading a flag through the initializer so that Ohai::System can know if its coming from the cli or not and behave appropriately. There's also quite a mess with the Ohai::Log class being passed around to the workstation loader, and it initializes itself at class loading time and Chef::Application will inject state into Ohai::Log. I think the eager initialization at class loading time is to not lose early messages when run from the cli, but it means the Ohai::Log object is always initialized, so that isn't useful for determining if we have come from the cli or not. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/ohai/application.rb2
-rw-r--r--lib/ohai/log.rb2
-rw-r--r--lib/ohai/system.rb7
3 files changed, 6 insertions, 5 deletions
diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb
index 9f1c400f..f01cf842 100644
--- a/lib/ohai/application.rb
+++ b/lib/ohai/application.rb
@@ -88,7 +88,7 @@ class Ohai::Application
end
def run_application
- ohai = Ohai::System.new(config)
+ ohai = Ohai::System.new(config, cli: true)
ohai.all_plugins(@attributes)
if @attributes
diff --git a/lib/ohai/log.rb b/lib/ohai/log.rb
index c63f7abe..4fe837ac 100644
--- a/lib/ohai/log.rb
+++ b/lib/ohai/log.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 0e8f5b7d..6ce3cf2f 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +39,8 @@ module Ohai
attr_reader :provides_map
attr_reader :v6_dependency_solver
- def initialize(config = {})
+ def initialize(config = {}, cli: false)
+ @cli = cli
@plugin_path = ""
@config = config
reset_system
@@ -51,7 +52,7 @@ module Ohai
@v6_dependency_solver = Hash.new
configure_ohai
- configure_logging
+ configure_logging if @cli
@loader = Ohai::Loader.new(self)
@runner = Ohai::Runner.new(self, true)