Allow logging from Collection using Connection logger

This commit is contained in:
slloyd 2011-10-10 10:51:03 -07:00
parent f5f714a1a1
commit 92a2e86d9a
2 changed files with 11 additions and 0 deletions

View File

@ -86,6 +86,7 @@ module Mongo
@db, @name = db, name
@connection = @db.connection
@logger = @connection.logger
@cache_time = @db.cache_time
@cache = Hash.new(0)
unless pk_factory

View File

@ -124,5 +124,15 @@ class CollectionTest < Test::Unit::TestCase
@coll.ensure_index [["x", Mongo::DESCENDING], ["y", Mongo::DESCENDING]]
end
should "use the connection's logger" do
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
@db = @conn['testing']
@coll = @db.collection('books')
@logger.expects(:warn).with do |msg|
msg == "MONGODB [WARNING] test warning"
end
@coll.log(:warn, "test warning")
end
end
end