implement a little logger with log time and query
This commit is contained in:
parent
867bee63af
commit
a7ec07a957
|
@ -82,7 +82,7 @@ module Mongo
|
|||
when nil
|
||||
[['localhost', DEFAULT_PORT]]
|
||||
end
|
||||
@options = options
|
||||
@options = options.merge(:logger => Logger.new(STDOUT))
|
||||
end
|
||||
|
||||
# Return the Mongo::DB named +db_name+. The slave_ok and
|
||||
|
|
|
@ -135,6 +135,7 @@ module Mongo
|
|||
@semaphore = Object.new
|
||||
@semaphore.extend Mutex_m
|
||||
@socket = nil
|
||||
@logger = options[:logger]
|
||||
connect_to_master
|
||||
end
|
||||
|
||||
|
@ -512,8 +513,11 @@ module Mongo
|
|||
def send_to_db(message)
|
||||
connect_to_master if !connected? && @auto_reconnect
|
||||
begin
|
||||
t_start = Time.now
|
||||
@socket.print(message.buf.to_s)
|
||||
@socket.flush
|
||||
res = @socket.flush
|
||||
@logger.debug(" MONGODB (#{Time.now - t_start}s) #{message.query}")
|
||||
res
|
||||
rescue => ex
|
||||
close
|
||||
raise ex
|
||||
|
|
|
@ -111,5 +111,9 @@ module Mongo
|
|||
def contains_special_fields
|
||||
(@order_by != nil && @order_by.length > 0) || @explain || @hint || @snapshot
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#find(#{@selector.inspect})" + (@order_by ? ".sort(#{@order_by.inspect})" : "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue