improve logger and fix all test with logging system

This commit is contained in:
Cyril Mougel 2009-09-11 00:02:03 +02:00
parent 58e73589bd
commit 5860333ed4
7 changed files with 31 additions and 2 deletions

View File

@ -83,7 +83,13 @@ module Mongo
when nil when nil
[['localhost', DEFAULT_PORT]] [['localhost', DEFAULT_PORT]]
end end
@options = options.merge(:logger => Logger.new(STDOUT))
unless options[:logger]
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
options[:logger] = logger
end
@options = options
end end
# Return the Mongo::DB named +db_name+. The slave_ok and # Return the Mongo::DB named +db_name+. The slave_ok and

View File

@ -516,7 +516,7 @@ module Mongo
t_start = Time.now 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.query}") @logger.debug(" MONGODB (#{Time.now - t_start}s) #{message}") if @logger
res res
rescue => ex rescue => ex
close close

View File

@ -22,10 +22,16 @@ module Mongo
class InsertMessage < Message class InsertMessage < Message
def initialize(db_name, collection_name, check_keys=true, *objs) def initialize(db_name, collection_name, check_keys=true, *objs)
@collection_name = collection_name
@objs = objs
super(OP_INSERT) super(OP_INSERT)
write_int(0) write_int(0)
write_string("#{db_name}.#{collection_name}") write_string("#{db_name}.#{collection_name}")
objs.each { |o| write_doc(o, check_keys) } objs.each { |o| write_doc(o, check_keys) }
end end
def to_s
"db.#{@collection_name}.insert(#{@objs.inspect})"
end
end end
end end

View File

@ -27,6 +27,7 @@ module Mongo
def initialize(db_name, collection_name, query) def initialize(db_name, collection_name, query)
super(OP_QUERY) super(OP_QUERY)
@query = query @query = query
@collection_name = collection_name
write_int(0) write_int(0)
write_string("#{db_name}.#{collection_name}") write_string("#{db_name}.#{collection_name}")
write_int(query.number_to_skip) write_int(query.number_to_skip)
@ -69,5 +70,9 @@ module Mongo
def first_key(key) def first_key(key)
@first_key = key @first_key = key
end end
def to_s
"db.#{@collection_name}.#{@query}"
end
end end
end end

View File

@ -22,11 +22,16 @@ module Mongo
class RemoveMessage < Message class RemoveMessage < Message
def initialize(db_name, collection_name, sel) def initialize(db_name, collection_name, sel)
@collection_name = collection_name
super(OP_DELETE) super(OP_DELETE)
write_int(0) write_int(0)
write_string("#{db_name}.#{collection_name}") write_string("#{db_name}.#{collection_name}")
write_int(0) # flags? write_int(0) # flags?
write_doc(sel) write_doc(sel)
end end
def to_s
"#{@collection_name}.clear()"
end
end end
end end

View File

@ -22,6 +22,7 @@ module Mongo
class UpdateMessage < Message class UpdateMessage < Message
def initialize(db_name, collection_name, sel, obj, repsert) def initialize(db_name, collection_name, sel, obj, repsert)
@collection_name = collection_name
super(OP_UPDATE) super(OP_UPDATE)
write_int(0) write_int(0)
write_string("#{db_name}.#{collection_name}") write_string("#{db_name}.#{collection_name}")
@ -29,5 +30,9 @@ module Mongo
write_doc(sel) write_doc(sel)
write_doc(obj) write_doc(obj)
end end
def to_s
"db.#{@collection_name}.update(#{@sel.inspect}, #{@obj.inspect})"
end
end end
end end

View File

@ -88,6 +88,8 @@ module Mongo
str str
end end
def inspect; to_s; end
# Get a string representation of this ObjectID using the legacy byte # Get a string representation of this ObjectID using the legacy byte
# ordering. This method may eventually be removed. If you are not sure # ordering. This method may eventually be removed. If you are not sure
# that you need this method you should be using the regular to_s. # that you need this method you should be using the regular to_s.