Global logger #18

Closed
wants to merge 2 commits into
from
View
3 README.md
@@ -117,6 +117,9 @@ you are good to go.
# Before you can use it, you will need to define a logger and
# provide it with the `:name` of your class.
Yell.new :stdout, :name => 'Foo'
+# As alternative you can register a global logger
+# which is gonna be used if no named logger for a class found
+Yell.new :stdout, :name => :global
class Foo
include Yell::Loggable
View
2 lib/yell/repository.rb
@@ -38,7 +38,7 @@ def []=( name, logger )
# @raise [Yell::LoggerNotFound] Raised when repository does not have that key
# @return [Yell::Logger] The logger instance
def []( name )
- synchronize { instance.fetch(name) or raise Yell::LoggerNotFound.new(name) }
+ synchronize { instance.fetch(name) or instance.fetch(:global) or raise Yell::LoggerNotFound.new(name) }
end
# Get the list of all loggers in the repository
View
14 spec/yell/repository_spec.rb
@@ -18,6 +18,20 @@
subject.should == logger
end
+ context "with a global logger" do
+ before do
+ @logger = Yell.new :stdout, :name => :global
+ end
+
+ it "should not raise with any name supplied" do
+ lambda { Yell::Repository[ String ] }.should_not raise_error
+ end
+
+ it "should return the global logger" do
+ Yell::Repository[ Numeric ].should == @logger
+ end
+ end
+
context "given a Class" do
before do
@logger = Yell.new :stdout, :name => "Numeric"