Skip to content

Commit

Permalink
Merge e73a68f into 9212b5e
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Filimonov committed May 31, 2013
2 parents 9212b5e + e73a68f commit 89bb117
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/yell/repository.rb
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/yell/repository_spec.rb
Expand Up @@ -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"
Expand Down

0 comments on commit 89bb117

Please sign in to comment.