diff options
author | Thom May <thom@chef.io> | 2016-08-12 18:19:11 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-08-12 18:19:11 +0100 |
commit | 3f74501b75e8f0c7745ea5fe170ebc9f43e89e96 (patch) | |
tree | df340e77cab67734a8be543a6f182b97bd03909b | |
parent | 44b302fa7f3e503d68eb4f458846f679900aab2f (diff) | |
download | mixlib-log-3f74501b75e8f0c7745ea5fe170ebc9f43e89e96.tar.gz |
Allow applications to query if they've got loggers
This is required to avoid the problems in #17
Signed-off-by: Thom May <thom@may.lt>
-rw-r--r-- | lib/mixlib/log.rb | 7 | ||||
-rw-r--r-- | spec/mixlib/log_spec.rb | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/mixlib/log.rb b/lib/mixlib/log.rb index 5ec1ba0..7152a90 100644 --- a/lib/mixlib/log.rb +++ b/lib/mixlib/log.rb @@ -66,6 +66,7 @@ module Mixlib "You gave: #{other.inspect}" raise ArgumentError, msg end + @configured = true end # Use Mixlib::Log.init when you want to set up the logger manually. Arguments to this method @@ -80,9 +81,15 @@ module Mixlib @logger = logger_for(*opts) @logger.formatter = Mixlib::Log::Formatter.new() if @logger.respond_to?(:formatter=) @logger.level = Logger::WARN + @configured = true @logger end + # Let the application query if logging objects have been set up + def configured? + @configured + end + # Sets the level for the Logger object by symbol. Valid arguments are: # # :debug diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb index 1eceff1..d780b0d 100644 --- a/spec/mixlib/log_spec.rb +++ b/spec/mixlib/log_spec.rb @@ -79,6 +79,11 @@ describe Mixlib::Log do expect(second_logdev.string).to match(/SECOND/) end + it "knows that it's been configured" do + Logit.init + expect(Logit.configured?).to be true + end + it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do levels = { :debug => Logger::DEBUG, |