summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mixlib/log.rb2
-rw-r--r--lib/mixlib/log/logger.rb2
-rw-r--r--spec/mixlib/log_spec.rb13
3 files changed, 12 insertions, 5 deletions
diff --git a/lib/mixlib/log.rb b/lib/mixlib/log.rb
index 18cdfd3..599ac57 100644
--- a/lib/mixlib/log.rb
+++ b/lib/mixlib/log.rb
@@ -170,7 +170,7 @@ module Mixlib
def logger_for(*opts)
if opts.empty?
- Mixlib::Log::Logger.new(STDOUT)
+ Mixlib::Log::Logger.new($stdout)
elsif LEVELS.keys.inject(true) { |quacks, level| quacks && opts.first.respond_to?(level) }
opts.first
else
diff --git a/lib/mixlib/log/logger.rb b/lib/mixlib/log/logger.rb
index f92d4a2..f227f23 100644
--- a/lib/mixlib/log/logger.rb
+++ b/lib/mixlib/log/logger.rb
@@ -21,7 +21,7 @@ module Mixlib
#
# +logdev+::
# The log device. This is a filename (String) or IO object (typically
- # +STDOUT+, +STDERR+, or an open file).
+ # +$stdout+, +$stderr+, or an open file).
# +shift_age+::
# Number of old log files to keep, *or* frequency of rotation (+daily+,
# +weekly+ or +monthly+).
diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb
index bbf290b..b58c4e2 100644
--- a/spec/mixlib/log_spec.rb
+++ b/spec/mixlib/log_spec.rb
@@ -142,9 +142,14 @@ RSpec.describe Mixlib::Log do
end
it "should pass other method calls directly to logger" do
- Logit.level = :debug
- expect(Logit).to be_debug
- expect { Logit.debug("Gimme some sugar!") }.to_not raise_error
+ expect do
+ # this needs to be inside of the block because the level setting
+ # is causing the init, which grabs $stderr before rspec replaces
+ # it for output testing.
+ Logit.level = :debug
+ expect(Logit).to be_debug
+ Logit.debug("Gimme some sugar!")
+ end.to output(/DEBUG: Gimme some sugar!/).to_stdout
end
it "should pass add method calls directly to logger" do
@@ -158,6 +163,7 @@ RSpec.describe Mixlib::Log do
it "should default to STDOUT if init is called with no arguments" do
logger_mock = Struct.new(:formatter, :level).new
+ # intentionally STDOUT to avoid unfailable test
expect(Logger).to receive(:new).with(STDOUT).and_return(logger_mock)
Logit.init
end
@@ -203,6 +209,7 @@ RSpec.describe Mixlib::Log do
end
it "should return nil from its logging methods" do
+ # intentionally STDOUT to avoid unfailable test
expect(Logger).to receive(:new).with(STDOUT) { double("a-quiet-logger").as_null_object }
Logit.init