diff options
author | Daniel DeLeo <dan@opscode.com> | 2010-10-13 21:58:36 -0700 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2010-10-13 21:59:26 -0700 |
commit | f9fb2da9a9511c97a3552c153f77c3ff7c0754b5 (patch) | |
tree | c035d77d7ce3fa7c5fc49334f11c8b7c97d8ee0e /spec | |
parent | 42bfc83c42a384e1371b9d3bd4b3a48bbae3e9cf (diff) | |
download | mixlib-log-f9fb2da9a9511c97a3552c153f77c3ff7c0754b5.tar.gz |
[CHEF-1382] allow the logger to be reinitialized
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/log_spec.rb | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb index f07ff66..d064871 100644 --- a/spec/mixlib/log_spec.rb +++ b/spec/mixlib/log_spec.rb @@ -29,10 +29,21 @@ describe Mixlib::Log do end it "should accept regular options to Logger.new via init" do - tf = Tempfile.new("chef-test-log") - tf.open - lambda { Logit.init(STDOUT) }.should_not raise_error - lambda { Logit.init(tf) }.should_not raise_error + Tempfile.open("chef-test-log") do |tf| + lambda { Logit.init(STDOUT) }.should_not raise_error + lambda { Logit.init(tf) }.should_not raise_error + end + end + + it "should re-initialize the logger if init is called again" do + first_logdev, second_logdev = StringIO.new, StringIO.new + Logit.init(first_logdev) + Logit.fatal "FIRST" + first_logdev.string.should match(/FIRST/) + Logit.init(second_logdev) + Logit.fatal "SECOND" + first_logdev.string.should_not match(/SECOND/) + second_logdev.string.should match(/SECOND/) end it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do @@ -49,7 +60,15 @@ describe Mixlib::Log do Logit.level.should == symbol end end - + + it "passes blocks to the underlying logger object" do + logdev = StringIO.new + Logit.init(logdev) + Logit.fatal { "the_message" } + logdev.string.should match(/the_message/) + end + + it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do levels = { :debug => Logger::DEBUG, |