summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2020-02-13 11:49:46 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-13 18:16:35 +0000
commita84c09a19720b73cedb2e8ef7c5cfeedfa1c9761 (patch)
tree85ac46cd5f4ea6d5134560bf764fb9e6cf11fe4e /src/mongo/rpc
parent6df40e01f7b6899affc4536e7e73a35802cabf98 (diff)
downloadmongo-a84c09a19720b73cedb2e8ef7c5cfeedfa1c9761.tar.gz
SERVER-45869 automatically converted structured logging
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/op_msg.cpp18
-rw-r--r--src/mongo/rpc/op_msg_integration_test.cpp8
-rw-r--r--src/mongo/rpc/op_msg_test.cpp19
3 files changed, 33 insertions, 12 deletions
diff --git a/src/mongo/rpc/op_msg.cpp b/src/mongo/rpc/op_msg.cpp
index e0a8d60881c..b20e269283b 100644
--- a/src/mongo/rpc/op_msg.cpp
+++ b/src/mongo/rpc/op_msg.cpp
@@ -39,6 +39,7 @@
#include "mongo/base/data_type_endian.h"
#include "mongo/config.h"
#include "mongo/db/bson/dotted_path_support.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/object_check.h"
#include "mongo/util/bufreader.h"
#include "mongo/util/hex.h"
@@ -218,8 +219,14 @@ OpMsg OpMsg::parse(const Message& message) try {
return msg;
} catch (const DBException& ex) {
- LOG(1) << "invalid message: " << ex.code() << " " << redact(ex) << " -- "
- << redact(hexdump(message.singleData().view2ptr(), message.size()));
+ LOGV2_DEBUG(
+ 22632,
+ 1,
+ "invalid message: {ex_code} {ex} -- {hexdump_message_singleData_view2ptr_message_size}",
+ "ex_code"_attr = ex.code(),
+ "ex"_attr = redact(ex),
+ "hexdump_message_singleData_view2ptr_message_size"_attr =
+ redact(hexdump(message.singleData().view2ptr(), message.size())));
throw;
}
@@ -291,8 +298,11 @@ Message OpMsgBuilder::finish() {
std::set<StringData> seenFields;
for (auto elem : resumeBody().asTempObj()) {
if (!(seenFields.insert(elem.fieldNameStringData()).second)) {
- severe() << "OP_MSG with duplicate field '" << elem.fieldNameStringData()
- << "' : " << redact(resumeBody().asTempObj());
+ LOGV2_FATAL(22633,
+ "OP_MSG with duplicate field '{elem_fieldNameStringData}' : "
+ "{resumeBody_asTempObj}",
+ "elem_fieldNameStringData"_attr = elem.fieldNameStringData(),
+ "resumeBody_asTempObj"_attr = redact(resumeBody().asTempObj()));
fassert(40474, false);
}
}
diff --git a/src/mongo/rpc/op_msg_integration_test.cpp b/src/mongo/rpc/op_msg_integration_test.cpp
index 3e9125c00a6..68dc5fa259b 100644
--- a/src/mongo/rpc/op_msg_integration_test.cpp
+++ b/src/mongo/rpc/op_msg_integration_test.cpp
@@ -27,16 +27,20 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/client/dbclient_connection.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/query/getmore_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/unittest/integration_test.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -694,14 +698,14 @@ TEST(OpMsg, ExhaustWithDBClientCursorBehavesCorrectly) {
conn->dropCollection(nss.toString());
const int nDocs = 5;
- unittest::log() << "Inserting " << nDocs << " documents.";
+ LOGV2(22634, "Inserting {nDocs} documents.", "nDocs"_attr = nDocs);
for (int i = 0; i < nDocs; i++) {
auto doc = BSON("_id" << i);
conn->insert(nss.toString(), doc);
}
ASSERT_EQ(conn->count(nss), size_t(nDocs));
- unittest::log() << "Finished document insertion.";
+ LOGV2(22635, "Finished document insertion.");
// Open an exhaust cursor.
int batchSize = 2;
diff --git a/src/mongo/rpc/op_msg_test.cpp b/src/mongo/rpc/op_msg_test.cpp
index c534dbdb702..8ad5723e6ce 100644
--- a/src/mongo/rpc/op_msg_test.cpp
+++ b/src/mongo/rpc/op_msg_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/bson/json.h"
#include "mongo/bson/util/builder.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
@@ -661,12 +662,18 @@ void testSerializer(const Message& fromSerializer, OpMsgBytes&& expected) {
std::mismatch(gotSD.begin(), gotSD.end(), expectedSD.begin(), expectedSD.end()).first -
gotSD.begin();
- log() << "Mismatch after " << commonLength << " bytes.";
- log() << "Common prefix: " << hexdump(gotSD.rawData(), commonLength);
- log() << "Got suffix : "
- << hexdump(gotSD.rawData() + commonLength, gotSD.size() - commonLength);
- log() << "Expected suffix: "
- << hexdump(expectedSD.rawData() + commonLength, expectedSD.size() - commonLength);
+ LOGV2(22636, "Mismatch after {commonLength} bytes.", "commonLength"_attr = commonLength);
+ LOGV2(22637,
+ "Common prefix: {hexdump_gotSD_rawData_commonLength}",
+ "hexdump_gotSD_rawData_commonLength"_attr = hexdump(gotSD.rawData(), commonLength));
+ LOGV2(22638,
+ "Got suffix : {hexdump_gotSD_rawData_commonLength_gotSD_size_commonLength}",
+ "hexdump_gotSD_rawData_commonLength_gotSD_size_commonLength"_attr =
+ hexdump(gotSD.rawData() + commonLength, gotSD.size() - commonLength));
+ LOGV2(22639,
+ "Expected suffix: {hexdump_expectedSD_rawData_commonLength_expectedSD_size_commonLength}",
+ "hexdump_expectedSD_rawData_commonLength_expectedSD_size_commonLength"_attr =
+ hexdump(expectedSD.rawData() + commonLength, expectedSD.size() - commonLength));
FAIL("Serialization didn't match expected data. See above for details.");
}