Permalink
Browse files

log messages read like valid ruby driver code

  • Loading branch information...
1 parent bca5daa commit bff177f3e2a3486d28f1b1d42bda96f0488e2f05 @banker banker committed Mar 24, 2010
Showing with 13 additions and 13 deletions.
  1. +6 −6 lib/mongo/collection.rb
  2. +2 −2 lib/mongo/cursor.rb
  3. +1 −1 test/connection_test.rb
  4. +4 −4 test/unit/collection_test.rb
@@ -265,13 +265,13 @@ def remove(selector={}, opts={})
if opts[:safe]
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name,
- "db.#{@db.name}.remove(#{selector.inspect})")
+ "#{@db.name}['#{@name}'].remove(#{selector.inspect})")
# the return value of send_message_with_safe_check isn't actually meaningful --
# only the fact that it didn't raise an error is -- so just return true
true
else
@connection.send_message(Mongo::Constants::OP_DELETE, message,
- "db.#{@db.name}.remove(#{selector.inspect})")
+ "#{@db.name}['#{@name}'].remove(#{selector.inspect})")
end
end
@@ -307,10 +307,10 @@ def update(selector, document, options={})
message.put_array(BSON.serialize(document, false, true).to_a)
if options[:safe]
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
- "db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
+ "#{@db.name}['#{@name}'].update(#{selector.inspect}, #{document.inspect})")
else
@connection.send_message(Mongo::Constants::OP_UPDATE, message,
- "db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
+ "#{@db.name}['#{@name}'].update(#{selector.inspect}, #{document.inspect})")
end
end
@@ -634,10 +634,10 @@ def insert_documents(documents, collection_name=@name, check_keys=true, safe=fal
documents.each { |doc| message.put_array(BSON.serialize(doc, check_keys, true).to_a) }
if safe
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name,
- "db.#{collection_name}.insert(#{documents.inspect})")
+ "#{@db.name}['#{collection_name}'].insert(#{documents.inspect})")
else
@connection.send_message(Mongo::Constants::OP_INSERT, message,
- "db.#{collection_name}.insert(#{documents.inspect})")
+ "#{@db.name}['#{collection_name}'].insert(#{documents.inspect})")
end
documents.collect { |o| o[:_id] || o['_id'] }
end
View
@@ -230,7 +230,7 @@ def close
message = ByteBuffer.new([0, 0, 0, 0])
message.put_int(1)
message.put_long(@cursor_id)
- @connection.send_message(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close()")
+ @connection.send_message(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close")
end
@cursor_id = 0
@closed = true
@@ -362,7 +362,7 @@ def construct_query_message
end
def query_log_message
- "#{@admin ? 'admin' : @db.name}.#{@collection.name}.find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
+ "#{@admin ? 'admin' : @db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" +
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
end
@@ -93,7 +93,7 @@ def test_logging
logger = Logger.new(output)
logger.level = Logger::DEBUG
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
- assert output.string.include?("admin.$cmd.find")
+ assert output.string.include?("admin['$cmd'].find")
end
def test_connection_logger
@@ -12,7 +12,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message).with do |op, msg, log|
- op == 2001 && log.include?("db.books.update")
+ op == 2001 && log.include?("testing['books'].update")
end
@coll.update({}, {:title => 'Moby Dick'})
end
@@ -22,7 +22,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message).with do |op, msg, log|
- op == 2002 && log.include?("db.books.insert")
+ op == 2002 && log.include?("testing['books'].insert")
end
@coll.insert({:title => 'Moby Dick'})
end
@@ -53,7 +53,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
- op == 2001 && log.include?("db.books.update")
+ op == 2001 && log.include?("testing['books'].update")
end
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
end
@@ -63,7 +63,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
- op == 2001 && log.include?("db.books.update")
+ op == 2001 && log.include?("testing['books'].update")
end
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
end

0 comments on commit bff177f

Please sign in to comment.