diff options
author | Nikhil Benesch <nikhil.benesch@gmail.com> | 2014-01-13 01:52:14 -0500 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2014-01-20 16:58:41 -0800 |
commit | b7d801cae217216b74df0bcfcb04518e15319a9c (patch) | |
tree | 218b73ba3b3c0bb1bf41322ec193c82c6c4b5941 | |
parent | 6a4b9a7849f4c60fdd2b016b288e01f2a6fd03f2 (diff) | |
download | chef-b7d801cae217216b74df0bcfcb04518e15319a9c.tar.gz |
CHEF-4725: Disable buffering on all log streams
Centralize handling of log buffering to ensure it's always disabled.
Previously, an unconfigured 'log_location' setting would erroneously
fall back to a default STDOUT stream with output buffering enabled.
-rw-r--r-- | lib/chef/application.rb | 1 | ||||
-rw-r--r-- | lib/chef/application/windows_service.rb | 1 | ||||
-rw-r--r-- | lib/chef/monologger.rb | 3 | ||||
-rw-r--r-- | spec/unit/monologger_spec.rb | 6 |
4 files changed, 7 insertions, 4 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index 4e6b29cec6..eba24ea17c 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -125,7 +125,6 @@ class Chef::Application def configure_stdout_logger stdout_logger = MonoLogger.new(STDOUT) - STDOUT.sync = true stdout_logger.formatter = Chef::Log.logger.formatter Chef::Log.loggers << stdout_logger end diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 4c99e50b0e..bea5e9fcdc 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -233,7 +233,6 @@ class Chef def configure_stdout_logger stdout_logger = MonoLogger.new(STDOUT) - STDOUT.sync = true stdout_logger.formatter = Chef::Log.logger.formatter Chef::Log.loggers << stdout_logger end diff --git a/lib/chef/monologger.rb b/lib/chef/monologger.rb index fed60514d7..464b21bdd3 100644 --- a/lib/chef/monologger.rb +++ b/lib/chef/monologger.rb @@ -48,9 +48,9 @@ class MonoLogger < Logger @dev = log else @dev = open_logfile(log) - @dev.sync = true @filename = log end + @dev.sync = true end def write(message) @@ -75,7 +75,6 @@ class MonoLogger < Logger def create_logfile(filename) logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT)) - logdev.sync = true add_log_header(logdev) logdev end diff --git a/spec/unit/monologger_spec.rb b/spec/unit/monologger_spec.rb index 38b23f22c6..3babc29218 100644 --- a/spec/unit/monologger_spec.rb +++ b/spec/unit/monologger_spec.rb @@ -20,6 +20,12 @@ require 'tempfile' require 'spec_helper' describe MonoLogger do + it "should disable buffering when passed an IO stream" do + STDOUT.sync = false + MonoLogger.new(STDOUT) + STDOUT.sync.should == true + end + describe "when given an object that responds to write and close e.g. IO" do it "should use the object directly" do stream = StringIO.new |