no logger by default. don't log timing because it's misleading for queries. add tests and documentation for logger
This commit is contained in:
parent
5860333ed4
commit
903e7136cf
@ -15,7 +15,6 @@
|
|||||||
# ++
|
# ++
|
||||||
|
|
||||||
require 'mongo/db'
|
require 'mongo/db'
|
||||||
require 'logger'
|
|
||||||
|
|
||||||
module Mongo
|
module Mongo
|
||||||
|
|
||||||
@ -48,6 +47,8 @@ module Mongo
|
|||||||
# automatically try to reconnect to the master or
|
# automatically try to reconnect to the master or
|
||||||
# to the single server we have been given. Defaults
|
# to the single server we have been given. Defaults
|
||||||
# to +false+.
|
# to +false+.
|
||||||
|
# :logger :: Optional Logger instance to which driver usage information
|
||||||
|
# will be logged.
|
||||||
#
|
#
|
||||||
# Since that's so confusing, here are a few examples:
|
# Since that's so confusing, here are a few examples:
|
||||||
#
|
#
|
||||||
@ -84,11 +85,6 @@ module Mongo
|
|||||||
[['localhost', DEFAULT_PORT]]
|
[['localhost', DEFAULT_PORT]]
|
||||||
end
|
end
|
||||||
|
|
||||||
unless options[:logger]
|
|
||||||
logger = Logger.new(STDOUT)
|
|
||||||
logger.level = Logger::INFO
|
|
||||||
options[:logger] = logger
|
|
||||||
end
|
|
||||||
@options = options
|
@options = options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,6 +107,8 @@ module Mongo
|
|||||||
# automatically try to reconnect to the master or
|
# automatically try to reconnect to the master or
|
||||||
# to the single server we have been given. Defaults
|
# to the single server we have been given. Defaults
|
||||||
# to +false+.
|
# to +false+.
|
||||||
|
# :logger :: Optional Logger instance to which driver usage information
|
||||||
|
# will be logged.
|
||||||
#
|
#
|
||||||
# When a DB object first connects to a pair, it will find the master
|
# When a DB object first connects to a pair, it will find the master
|
||||||
# instance and connect to that one. On socket error or if we recieve a
|
# instance and connect to that one. On socket error or if we recieve a
|
||||||
@ -513,10 +515,9 @@ module Mongo
|
|||||||
def send_to_db(message)
|
def send_to_db(message)
|
||||||
connect_to_master if !connected? && @auto_reconnect
|
connect_to_master if !connected? && @auto_reconnect
|
||||||
begin
|
begin
|
||||||
t_start = Time.now
|
|
||||||
@socket.print(message.buf.to_s)
|
@socket.print(message.buf.to_s)
|
||||||
res = @socket.flush
|
res = @socket.flush
|
||||||
@logger.debug(" MONGODB (#{Time.now - t_start}s) #{message}") if @logger
|
@logger.debug(" MONGODB #{message}") if @logger
|
||||||
res
|
res
|
||||||
rescue => ex
|
rescue => ex
|
||||||
close
|
close
|
||||||
|
@ -113,7 +113,7 @@ module Mongo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#find(#{@selector.inspect})" + (@order_by ? ".sort(#{@order_by.inspect})" : "")
|
"find(#{@selector.inspect})" + (@order_by ? ".sort(#{@order_by.inspect})" : "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||||
require 'mongo'
|
require 'mongo'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require 'logger'
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
# NOTE: assumes Mongo is running
|
# NOTE: assumes Mongo is running
|
||||||
class TestConnection < Test::Unit::TestCase
|
class TestConnection < Test::Unit::TestCase
|
||||||
@ -54,6 +56,17 @@ class TestConnection < Test::Unit::TestCase
|
|||||||
@mongo.drop_database('ruby-mongo-info-test')
|
@mongo.drop_database('ruby-mongo-info-test')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_logging
|
||||||
|
output = StringIO.new
|
||||||
|
logger = Logger.new(output)
|
||||||
|
logger.level = Logger::DEBUG
|
||||||
|
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
|
||||||
|
db['test'].find().to_a
|
||||||
|
|
||||||
|
assert output.string.include?("db.test.find")
|
||||||
|
assert !output.string.include?("db.test.remove")
|
||||||
|
end
|
||||||
|
|
||||||
def test_drop_database
|
def test_drop_database
|
||||||
db = @mongo.db('ruby-mongo-will-be-deleted')
|
db = @mongo.db('ruby-mongo-will-be-deleted')
|
||||||
coll = db.collection('temp')
|
coll = db.collection('temp')
|
||||||
|
Loading…
Reference in New Issue
Block a user