Skip to content

Commit

Permalink
Allow applications to query if they've got loggers
Browse files Browse the repository at this point in the history
This is required to avoid the problems in #17

Signed-off-by: Thom May <[email protected]>
  • Loading branch information
Thom May committed Aug 12, 2016
1 parent 44b302f commit 3f74501
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/mixlib/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def use_log_devices(other)
"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
Expand All @@ -80,9 +81,15 @@ def init(*opts)
@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
Expand Down
5 changes: 5 additions & 0 deletions spec/mixlib/log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def #{method_name}(message)
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,
Expand Down

0 comments on commit 3f74501

Please sign in to comment.