diff options
-rw-r--r-- | lib/chef/application/windows_service.rb | 14 | ||||
-rw-r--r-- | spec/unit/windows_service_spec.rb | 7 |
2 files changed, 11 insertions, 10 deletions
diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 932f7e9c36..2f938059ca 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -188,7 +188,11 @@ class Chef # Pass config params to the new process config_params = " --no-fork" config_params += " -c #{Chef::Config[:config_file]}" unless Chef::Config[:config_file].nil? - config_params += " -L #{resolve_log_location}" unless Chef::Config[:log_location] == STDOUT + # log_location might be an event logger and if so we cannot pass as a command argument + # but shed no tears! If the logger is an event logger, it must have been configured + # as such in the config file and chef-client will use that when no arg is passed here + config_params += " -L #{resolve_log_location}" if resolve_log_location.is_a?(String) + # Starts a new process and waits till the process exits result = shell_out( @@ -266,13 +270,9 @@ class Chef Chef::Config[:log_level] == :auto end - # Check if we have a log location and it's not STDOUT def resolve_log_location - if Chef::Config[:log_location] && Chef::Config[:log_location].is_a?(String) - Chef::Config[:log_location] - else - DEFAULT_LOG_LOCATION - end + # STDOUT is the default log location, but makes no sense for a windows service + Chef::Config[:log_location] == STDOUT ? DEFAULT_LOG_LOCATION : Chef::Config[:log_location] end # if log_level is `:auto`, convert it to :warn (when using output formatter) diff --git a/spec/unit/windows_service_spec.rb b/spec/unit/windows_service_spec.rb index d4f2da9892..031a3124f8 100644 --- a/spec/unit/windows_service_spec.rb +++ b/spec/unit/windows_service_spec.rb @@ -24,6 +24,7 @@ describe "Chef::Application::WindowsService", :windows_only do let(:shell_out_result) { double('shellout', stdout: nil, stderr: nil) } let(:config_options) do { + log_location: STDOUT, config_file: "test_config_file", log_level: :info } @@ -48,7 +49,7 @@ describe "Chef::Application::WindowsService", :windows_only do subject { Chef::Application::WindowsService.new } - it "passes config params to new process with default options" do + it "passes DEFAULT_LOG_LOCATION to chef-client instead of STDOUT" do expect(subject).to receive(:shell_out).with( "chef-client --no-fork -c test_config_file -L #{Chef::Application::WindowsService::DEFAULT_LOG_LOCATION}", shellout_options @@ -78,10 +79,10 @@ describe "Chef::Application::WindowsService", :windows_only do subject.service_main end - context 'configured to STDOUT' do + context 'configured to Event Logger' do let(:config_options) do { - log_location: STDOUT, + log_location: Chef::Log::WinEvt.new, config_file: "test_config_file", log_level: :info } |