Added logger convenience methods to connection and database. Makes it possible to use the logger instance in the driver from the outside world.
This commit is contained in:
parent
1fc537c78e
commit
89d420780f
@ -95,6 +95,10 @@ module Mongo
|
||||
DB.new(db_name, @pair, @options.merge(options))
|
||||
end
|
||||
|
||||
def logger
|
||||
@options[:logger]
|
||||
end
|
||||
|
||||
# Returns a hash containing database names as keys and disk space for
|
||||
# each as values.
|
||||
def database_info
|
||||
|
@ -59,6 +59,9 @@ module Mongo
|
||||
# The database's socket. For internal (and Cursor) use only.
|
||||
attr_reader :socket
|
||||
|
||||
# The logger instance if :logger is passed to initialize
|
||||
attr_reader :logger
|
||||
|
||||
def slave_ok?; @slave_ok; end
|
||||
def auto_reconnect?; @auto_reconnect; end
|
||||
|
||||
|
@ -67,6 +67,17 @@ class TestConnection < Test::Unit::TestCase
|
||||
assert !output.string.include?("db.test.remove")
|
||||
end
|
||||
|
||||
def test_connection_logger
|
||||
output = StringIO.new
|
||||
logger = Logger.new(output)
|
||||
logger.level = Logger::DEBUG
|
||||
connection = Connection.new(@host, @port, :logger => logger)
|
||||
assert_equal logger, connection.logger
|
||||
|
||||
connection.logger.debug 'testing'
|
||||
assert output.string.include?('testing')
|
||||
end
|
||||
|
||||
def test_drop_database
|
||||
db = @mongo.db('ruby-mongo-will-be-deleted')
|
||||
coll = db.collection('temp')
|
||||
|
@ -2,6 +2,8 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
require 'digest/md5'
|
||||
require 'mongo'
|
||||
require 'test/unit'
|
||||
require 'stringio'
|
||||
require 'logger'
|
||||
|
||||
class TestPKFactory
|
||||
def create_pk(row)
|
||||
@ -46,6 +48,17 @@ class DBTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_logger
|
||||
output = StringIO.new
|
||||
logger = Logger.new(output)
|
||||
logger.level = Logger::DEBUG
|
||||
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
|
||||
assert_equal logger, db.logger
|
||||
|
||||
db.logger.debug 'testing'
|
||||
assert output.string.include?('testing')
|
||||
end
|
||||
|
||||
def test_full_coll_name
|
||||
coll = @@db.collection('test')
|
||||
assert_equal 'ruby-mongo-test.test', @@db.full_coll_name(coll.name)
|
||||
|
Loading…
Reference in New Issue
Block a user