summaryrefslogtreecommitdiff
path: root/src/mongo/platform
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/platform
parent6df40e01f7b6899affc4536e7e73a35802cabf98 (diff)
downloadmongo-a84c09a19720b73cedb2e8ef7c5cfeedfa1c9761.tar.gz
SERVER-45869 automatically converted structured logging
Diffstat (limited to 'src/mongo/platform')
-rw-r--r--src/mongo/platform/decimal128_bson_test.cpp5
-rw-r--r--src/mongo/platform/random_test.cpp17
-rw-r--r--src/mongo/platform/shared_library_posix.cpp7
-rw-r--r--src/mongo/platform/shared_library_windows.cpp11
-rw-r--r--src/mongo/platform/source_location_test.cpp38
5 files changed, 51 insertions, 27 deletions
diff --git a/src/mongo/platform/decimal128_bson_test.cpp b/src/mongo/platform/decimal128_bson_test.cpp
index dd6c2dd2018..6f0313f1d12 100644
--- a/src/mongo/platform/decimal128_bson_test.cpp
+++ b/src/mongo/platform/decimal128_bson_test.cpp
@@ -42,6 +42,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
#include "mongo/db/json.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
@@ -94,7 +95,7 @@ TEST(Decimal128BSONTest, TestsConstructingDecimalWithBsonDump) {
BSONElement extjson = b.getField("extjson");
BSONElement canonical_extjson = b.getField("canonical_extjson");
- log() << "Test - " << desc.str();
+ LOGV2(22609, "Test - {desc_str}", "desc_str"_attr = desc.str());
StringData hexString = bson.valueStringData();
BSONObj d = convertHexStringToBsonObj(hexString);
@@ -108,7 +109,7 @@ TEST(Decimal128BSONTest, TestsConstructingDecimalWithBsonDump) {
}
ASSERT_EQ(trimWhiteSpace(outputJson), trimWhiteSpace(expectedJson));
- log() << "PASSED";
+ LOGV2(22610, "PASSED");
}
}
}
diff --git a/src/mongo/platform/random_test.cpp b/src/mongo/platform/random_test.cpp
index c3271f8b926..f4bf565d700 100644
--- a/src/mongo/platform/random_test.cpp
+++ b/src/mongo/platform/random_test.cpp
@@ -27,12 +27,16 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include <set>
#include <vector>
#include "mongo/platform/random.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
@@ -233,11 +237,14 @@ TEST(RandomTest, NextInt32Uniformity) {
if (kDebugBuild) {
for (size_t i = 0; i < hist.size(); ++i) {
double dev = std::pow(std::pow((hist[i] - mu) / mu, 2), .5);
- unittest::log() << format(FMT_STRING(" [{:4}] count:{:4}, dev:{:6f}, {}"),
- i,
- hist[i],
- dev,
- std::string(hist[i] / 256, '*'));
+ LOGV2(22611,
+ "{format_FMT_STRING_4_count_4_dev_6f_i_hist_i_dev_std_string_hist_i_256}",
+ "format_FMT_STRING_4_count_4_dev_6f_i_hist_i_dev_std_string_hist_i_256"_attr =
+ format(FMT_STRING(" [{:4}] count:{:4}, dev:{:6f}, {}"),
+ i,
+ hist[i],
+ dev,
+ std::string(hist[i] / 256, '*')));
}
}
for (size_t i = 0; i < hist.size(); ++i) {
diff --git a/src/mongo/platform/shared_library_posix.cpp b/src/mongo/platform/shared_library_posix.cpp
index 871bd697012..ee7e1eca829 100644
--- a/src/mongo/platform/shared_library_posix.cpp
+++ b/src/mongo/platform/shared_library_posix.cpp
@@ -36,6 +36,7 @@
#include <dlfcn.h>
#include <memory>
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -45,14 +46,16 @@ namespace mongo {
SharedLibrary::~SharedLibrary() {
if (_handle) {
if (dlclose(_handle) != 0) {
- LOG(2) << "Load Library close failed " << dlerror();
+ LOGV2_DEBUG(
+ 22612, 2, "Load Library close failed {dlerror}", "dlerror"_attr = dlerror());
}
}
}
StatusWith<std::unique_ptr<SharedLibrary>> SharedLibrary::create(
const boost::filesystem::path& full_path) {
- LOG(1) << "Loading library: " << full_path.c_str();
+ LOGV2_DEBUG(
+ 22613, 1, "Loading library: {full_path_c_str}", "full_path_c_str"_attr = full_path.c_str());
void* handle = dlopen(full_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (handle == nullptr) {
diff --git a/src/mongo/platform/shared_library_windows.cpp b/src/mongo/platform/shared_library_windows.cpp
index 504b366ab2e..9d9a261de59 100644
--- a/src/mongo/platform/shared_library_windows.cpp
+++ b/src/mongo/platform/shared_library_windows.cpp
@@ -34,6 +34,7 @@
#include <boost/filesystem.hpp>
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -45,14 +46,20 @@ SharedLibrary::~SharedLibrary() {
if (_handle) {
if (FreeLibrary(static_cast<HMODULE>(_handle)) == 0) {
DWORD lasterror = GetLastError();
- LOG(2) << "Load library close failed: " << errnoWithDescription(lasterror);
+ LOGV2_DEBUG(22614,
+ 2,
+ "Load library close failed: {errnoWithDescription_lasterror}",
+ "errnoWithDescription_lasterror"_attr = errnoWithDescription(lasterror));
}
}
}
StatusWith<std::unique_ptr<SharedLibrary>> SharedLibrary::create(
const boost::filesystem::path& full_path) {
- LOG(1) << "Loading library: " << toUtf8String(full_path.c_str());
+ LOGV2_DEBUG(22615,
+ 1,
+ "Loading library: {toUtf8String_full_path_c_str}",
+ "toUtf8String_full_path_c_str"_attr = toUtf8String(full_path.c_str()));
HMODULE handle = LoadLibraryW(full_path.c_str());
if (handle == nullptr) {
diff --git a/src/mongo/platform/source_location_test.cpp b/src/mongo/platform/source_location_test.cpp
index a702eda827e..5ba247fa807 100644
--- a/src/mongo/platform/source_location_test.cpp
+++ b/src/mongo/platform/source_location_test.cpp
@@ -27,9 +27,13 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/source_location_test.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace {
@@ -64,9 +68,9 @@ TEST(SourceLocation, InlineVariable) {
ASSERT_LT(inlineLocation1.line(), inlineLocation2.line());
ASSERT_LT(inlineLocation2.line(), inlineLocation3.line());
- unittest::log() << inlineLocation1;
- unittest::log() << inlineLocation2;
- unittest::log() << inlineLocation3;
+ LOGV2(22616, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22617, "{inlineLocation2}", "inlineLocation2"_attr = inlineLocation2);
+ LOGV2(22618, "{inlineLocation3}", "inlineLocation3"_attr = inlineLocation3);
}
TEST(SourceLocation, LocalFunction) {
@@ -81,9 +85,11 @@ TEST(SourceLocation, LocalFunction) {
// The two local function locations should be identical
ASSERT_EQ(localFunctionLocation1, localFunctionLocation2);
- unittest::log() << inlineLocation1;
- unittest::log() << localFunctionLocation1;
- unittest::log() << localFunctionLocation2;
+ LOGV2(22619, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(
+ 22620, "{localFunctionLocation1}", "localFunctionLocation1"_attr = localFunctionLocation1);
+ LOGV2(
+ 22621, "{localFunctionLocation2}", "localFunctionLocation2"_attr = localFunctionLocation2);
}
TEST(SourceLocation, HeaderFunction) {
@@ -97,9 +103,9 @@ TEST(SourceLocation, HeaderFunction) {
// The two header locations should be identical
ASSERT_EQ(headerLocation1, headerLocation2);
- unittest::log() << inlineLocation1;
- unittest::log() << headerLocation1;
- unittest::log() << headerLocation2;
+ LOGV2(22622, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22623, "{headerLocation1}", "headerLocation1"_attr = headerLocation1);
+ LOGV2(22624, "{headerLocation2}", "headerLocation2"_attr = headerLocation2);
}
TEST(SourceLocation, GlobalVariable) {
@@ -109,8 +115,8 @@ TEST(SourceLocation, GlobalVariable) {
ASSERT_EQ(inlineLocation1.file_name(), kLocation.file_name());
ASSERT_GT(inlineLocation1.line(), kLocation.line());
- unittest::log() << inlineLocation1;
- unittest::log() << kLocation;
+ LOGV2(22625, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22626, "{kLocation}", "kLocation"_attr = kLocation);
}
TEST(SourceLocation, DefaultStructMember) {
@@ -125,9 +131,9 @@ TEST(SourceLocation, DefaultStructMember) {
// The two default ctor'd struct member locations should be identical
ASSERT_EQ(obj1.location, obj2.location);
- unittest::log() << inlineLocation1;
- unittest::log() << obj1.location;
- unittest::log() << obj2.location;
+ LOGV2(22627, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22628, "{obj1_location}", "obj1_location"_attr = obj1.location);
+ LOGV2(22629, "{obj2_location}", "obj2_location"_attr = obj2.location);
}
TEST(SourceLocation, Macro) {
@@ -140,8 +146,8 @@ TEST(SourceLocation, Macro) {
// The line numbers for each location should increase monotonically when inline
ASSERT_LT(inlineLocation1.line(), inlineLocation2.line());
- unittest::log() << inlineLocation1;
- unittest::log() << inlineLocation2;
+ LOGV2(22630, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22631, "{inlineLocation2}", "inlineLocation2"_attr = inlineLocation2);
}
TEST(SourceLocation, Constexpr) {