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
|
when nil
|
||||||
[['localhost', DEFAULT_PORT]]
|
[['localhost', DEFAULT_PORT]]
|
||||||
end
|
end
|
||||||
@options = options
|
@options = options.merge(:logger => Logger.new(STDOUT))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the Mongo::DB named +db_name+. The slave_ok and
|
# Return the Mongo::DB named +db_name+. The slave_ok and
|
||||||
|
@ -135,6 +135,7 @@ module Mongo
|
|||||||
@semaphore = Object.new
|
@semaphore = Object.new
|
||||||
@semaphore.extend Mutex_m
|
@semaphore.extend Mutex_m
|
||||||
@socket = nil
|
@socket = nil
|
||||||
|
@logger = options[:logger]
|
||||||
connect_to_master
|
connect_to_master
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -512,8 +513,11 @@ 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)
|
||||||
@socket.flush
|
res = @socket.flush
|
||||||
|
@logger.debug(" MONGODB (#{Time.now - t_start}s) #{message.query}")
|
||||||
|
res
|
||||||
rescue => ex
|
rescue => ex
|
||||||
close
|
close
|
||||||
raise ex
|
raise ex
|
||||||
|
@ -111,5 +111,9 @@ module Mongo
|
|||||||
def contains_special_fields
|
def contains_special_fields
|
||||||
(@order_by != nil && @order_by.length > 0) || @explain || @hint || @snapshot
|
(@order_by != nil && @order_by.length > 0) || @explain || @hint || @snapshot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"#find(#{@selector.inspect})" + (@order_by ? ".sort(#{@order_by.inspect})" : "")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user