summaryrefslogtreecommitdiff
path: root/src/mongo/logger
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/logger')
-rw-r--r--src/mongo/logger/log_component.cpp80
-rw-r--r--src/mongo/logger/log_severity.cpp26
-rw-r--r--src/mongo/logger/log_test.cpp8
-rw-r--r--src/mongo/logger/message_event_utf8_encoder.cpp2
4 files changed, 54 insertions, 62 deletions
diff --git a/src/mongo/logger/log_component.cpp b/src/mongo/logger/log_component.cpp
index d64c4d8c66d..8b8db2e2c54 100644
--- a/src/mongo/logger/log_component.cpp
+++ b/src/mongo/logger/log_component.cpp
@@ -42,14 +42,6 @@ namespace {
// Lazily evaluated in LogComponent::getDottedName().
std::string _dottedNames[LogComponent::kNumLogComponents + 1];
-/**
- * Returns StringData created from a string literal
- */
-template <size_t N>
-StringData createStringData(const char (&val)[N]) {
- return StringData(val, StringData::LiteralTag());
-}
-
//
// Fully initialize _dottedNames before we enter multithreaded execution.
//
@@ -94,41 +86,41 @@ LogComponent LogComponent::parent() const {
StringData LogComponent::toStringData() const {
switch (_value) {
case kDefault:
- return createStringData("default");
+ return "default"_sd;
case kAccessControl:
- return createStringData("accessControl");
+ return "accessControl"_sd;
case kCommand:
- return createStringData("command");
+ return "command"_sd;
case kControl:
- return createStringData("control");
+ return "control"_sd;
case kExecutor:
- return createStringData("executor");
+ return "executor"_sd;
case kGeo:
- return createStringData("geo");
+ return "geo"_sd;
case kIndex:
- return createStringData("index");
+ return "index"_sd;
case kNetwork:
- return createStringData("network");
+ return "network"_sd;
case kQuery:
- return createStringData("query");
+ return "query"_sd;
case kReplication:
- return createStringData("replication");
+ return "replication"_sd;
case kSharding:
- return createStringData("sharding");
+ return "sharding"_sd;
case kStorage:
- return createStringData("storage");
+ return "storage"_sd;
case kJournal:
- return createStringData("journal");
+ return "journal"_sd;
case kWrite:
- return createStringData("write");
+ return "write"_sd;
case kFTDC:
- return createStringData("ftdc");
+ return "ftdc"_sd;
case kASIO:
- return createStringData("asio");
+ return "asio"_sd;
case kBridge:
- return createStringData("bridge");
+ return "bridge"_sd;
case kNumLogComponents:
- return createStringData("total");
+ return "total"_sd;
// No default. Compiler should complain if there's a log component that's not handled.
}
invariant(false);
@@ -164,41 +156,41 @@ std::string LogComponent::getDottedName() const {
StringData LogComponent::getNameForLog() const {
switch (_value) {
case kDefault:
- return createStringData("- ");
+ return "- "_sd;
case kAccessControl:
- return createStringData("ACCESS ");
+ return "ACCESS "_sd;
case kCommand:
- return createStringData("COMMAND ");
+ return "COMMAND "_sd;
case kControl:
- return createStringData("CONTROL ");
+ return "CONTROL "_sd;
case kExecutor:
- return createStringData("EXECUTOR");
+ return "EXECUTOR"_sd;
case kGeo:
- return createStringData("GEO ");
+ return "GEO "_sd;
case kIndex:
- return createStringData("INDEX ");
+ return "INDEX "_sd;
case kNetwork:
- return createStringData("NETWORK ");
+ return "NETWORK "_sd;
case kQuery:
- return createStringData("QUERY ");
+ return "QUERY "_sd;
case kReplication:
- return createStringData("REPL ");
+ return "REPL "_sd;
case kSharding:
- return createStringData("SHARDING");
+ return "SHARDING"_sd;
case kStorage:
- return createStringData("STORAGE ");
+ return "STORAGE "_sd;
case kJournal:
- return createStringData("JOURNAL ");
+ return "JOURNAL "_sd;
case kWrite:
- return createStringData("WRITE ");
+ return "WRITE "_sd;
case kFTDC:
- return createStringData("FTDC ");
+ return "FTDC "_sd;
case kASIO:
- return createStringData("ASIO ");
+ return "ASIO "_sd;
case kBridge:
- return createStringData("BRIDGE ");
+ return "BRIDGE "_sd;
case kNumLogComponents:
- return createStringData("TOTAL ");
+ return "TOTAL "_sd;
// No default. Compiler should complain if there's a log component that's not handled.
}
invariant(false);
diff --git a/src/mongo/logger/log_severity.cpp b/src/mongo/logger/log_severity.cpp
index cac38849be7..1f8a2d9bf01 100644
--- a/src/mongo/logger/log_severity.cpp
+++ b/src/mongo/logger/log_severity.cpp
@@ -35,28 +35,28 @@ namespace mongo {
namespace logger {
namespace {
-const char unknownSeverityString[] = "UNKNOWN";
-const char severeSeverityString[] = "SEVERE";
-const char errorSeverityString[] = "ERROR";
-const char warningSeverityString[] = "warning";
-const char infoSeverityString[] = "info";
-const char debugSeverityString[] = "debug";
+constexpr auto unknownSeverityString = "UNKNOWN"_sd;
+constexpr auto severeSeverityString = "SEVERE"_sd;
+constexpr auto errorSeverityString = "ERROR"_sd;
+constexpr auto warningSeverityString = "warning"_sd;
+constexpr auto infoSeverityString = "info"_sd;
+constexpr auto debugSeverityString = "debug"_sd;
} // namespace
StringData LogSeverity::toStringData() const {
if (_severity > 0)
- return StringData(debugSeverityString, StringData::LiteralTag());
+ return debugSeverityString;
if (*this == LogSeverity::Severe())
- return StringData(severeSeverityString, StringData::LiteralTag());
+ return severeSeverityString;
if (*this == LogSeverity::Error())
- return StringData(errorSeverityString, StringData::LiteralTag());
+ return errorSeverityString;
if (*this == LogSeverity::Warning())
- return StringData(warningSeverityString, StringData::LiteralTag());
+ return warningSeverityString;
if (*this == LogSeverity::Info())
- return StringData(infoSeverityString, StringData::LiteralTag());
+ return infoSeverityString;
if (*this == LogSeverity::Log())
- return StringData(infoSeverityString, StringData::LiteralTag());
- return StringData(unknownSeverityString, StringData::LiteralTag());
+ return infoSeverityString;
+ return unknownSeverityString;
}
char LogSeverity::toChar() const {
diff --git a/src/mongo/logger/log_test.cpp b/src/mongo/logger/log_test.cpp
index f4b8ec2bc34..5be29f5d74b 100644
--- a/src/mongo/logger/log_test.cpp
+++ b/src/mongo/logger/log_test.cpp
@@ -384,8 +384,8 @@ void testEncodedLogLine(const MessageEventEphemeral& event, const std::string& e
// Log severity should always be logged as a single capital letter.
TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogSeverity) {
Date_t d = Date_t::now();
- StringData ctx("WHAT", StringData::LiteralTag());
- StringData msg("HUH", StringData::LiteralTag());
+ const auto ctx = "WHAT"_sd;
+ const auto msg = "HUH"_sd;
// Severe is indicated by (F)atal.
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Severe(), ctx, msg), " F ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Error(), ctx, msg), " E ");
@@ -407,8 +407,8 @@ TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogSeverity) {
// Non-default log component short name should always be logged.
TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogComponent) {
Date_t d = Date_t::now();
- StringData ctx("WHAT", StringData::LiteralTag());
- StringData msg("HUH", StringData::LiteralTag());
+ const auto ctx = "WHAT"_sd;
+ const auto msg = "HUH"_sd;
for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
LogComponent component = static_cast<LogComponent::Value>(i);
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Info(), component, ctx, msg),
diff --git a/src/mongo/logger/message_event_utf8_encoder.cpp b/src/mongo/logger/message_event_utf8_encoder.cpp
index 3483a113d1e..827876d46f5 100644
--- a/src/mongo/logger/message_event_utf8_encoder.cpp
+++ b/src/mongo/logger/message_event_utf8_encoder.cpp
@@ -76,7 +76,7 @@ std::ostream& MessageEventDetailsEncoder::encode(const MessageEventEphemeral& ev
} else {
os << msg;
}
- if (!msg.endsWith(StringData("\n", StringData::LiteralTag())))
+ if (!msg.endsWith(StringData("\n"_sd)))
os << '\n';
return os;
}