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
[['localhost', DEFAULT_PORT]]
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
# Return the Mongo::DB named +db_name+. The slave_ok and

View File

@ -516,7 +516,7 @@ module Mongo
t_start = Time.now
@socket.print(message.buf.to_s)
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
rescue => ex
close

View File

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

View File

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

View File

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

View File

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

View File

@ -88,6 +88,8 @@ module Mongo
str
end
def inspect; to_s; end
# Get a string representation of this ObjectID using the legacy byte
# 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.