summaryrefslogtreecommitdiff
path: root/src/mongo/logger
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-07-16 12:35:13 -0400
committerBenety Goh <benety@mongodb.com>2014-07-29 17:42:21 -0400
commitc91a2c3392fc95be3ed07ba98a4d98b4db754b58 (patch)
tree255115ae0f8391766ca75441b30225f6a4194d34 /src/mongo/logger
parenta0dcb4026b3f1171b4124e2666cf71460d023bb1 (diff)
downloadmongo-c91a2c3392fc95be3ed07ba98a4d98b4db754b58.tar.gz
SERVER-4217 updated detailed log format to include log severity and component name.
Log severity is logged with a single capital letter. F - Severe E - Error W - Warning I - Info and Debug Level 0 D - All debug levels > 0 Component name is logged in upper-case padded with trailing spaces to fit within 8 characters.
Diffstat (limited to 'src/mongo/logger')
-rw-r--r--src/mongo/logger/log_component.cpp65
-rw-r--r--src/mongo/logger/log_component.h17
-rw-r--r--src/mongo/logger/log_severity.cpp20
-rw-r--r--src/mongo/logger/log_severity.h8
-rw-r--r--src/mongo/logger/log_test.cpp137
-rw-r--r--src/mongo/logger/logstream_builder.cpp18
-rw-r--r--src/mongo/logger/logstream_builder.h16
-rw-r--r--src/mongo/logger/message_event.h16
-rw-r--r--src/mongo/logger/message_event_utf8_encoder.cpp13
9 files changed, 275 insertions, 35 deletions
diff --git a/src/mongo/logger/log_component.cpp b/src/mongo/logger/log_component.cpp
index 349d0d6fd18..a7358c7f180 100644
--- a/src/mongo/logger/log_component.cpp
+++ b/src/mongo/logger/log_component.cpp
@@ -43,6 +43,14 @@ 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.
//
@@ -77,26 +85,30 @@ std::string _dottedNames[LogComponent::kNumLogComponents+1];
case kNumLogComponents: return kNumLogComponents;
default: return kDefault;
}
- invariant(0);
+ invariant(false);
}
- std::string LogComponent::getShortName() const {
+ StringData LogComponent::toStringData() const {
switch (_value) {
- case kDefault: return "default";
- case kAccessControl: return "accessControl";
- case kCommands: return "commands";
- case kIndexing: return "indexing";
- case kNetworking: return "networking";
- case kQuery: return "query";
- case kReplication: return "replication";
- case kSharding: return "sharding";
- case kStorage: return "storage";
- case kJournaling: return "journaling";
- case kWrites: return "writes";
- case kNumLogComponents: return "total";
+ case kDefault: return createStringData("default");
+ case kAccessControl: return createStringData("accessControl");
+ case kCommands: return createStringData("commands");
+ case kIndexing: return createStringData("indexing");
+ case kNetworking: return createStringData("networking");
+ case kQuery: return createStringData("query");
+ case kReplication: return createStringData("replication");
+ case kSharding: return createStringData("sharding");
+ case kStorage: return createStringData("storage");
+ case kJournaling: return createStringData("journaling");
+ case kWrites: return createStringData("writes");
+ case kNumLogComponents: return createStringData("total");
// No default. Compiler should complain if there's a log component that's not handled.
}
- invariant(0);
+ invariant(false);
+ }
+
+ std::string LogComponent::getShortName() const {
+ return toStringData().toString();
}
std::string LogComponent::getDottedName() const {
@@ -119,5 +131,28 @@ std::string _dottedNames[LogComponent::kNumLogComponents+1];
return _dottedNames[_value];
}
+ StringData LogComponent::getNameForLog() const {
+ switch (_value) {
+ case kDefault: return createStringData(" ");
+ case kAccessControl: return createStringData("ACCESS ");
+ case kCommands: return createStringData("COMMANDS");
+ case kIndexing: return createStringData("INDEXING");
+ case kNetworking: return createStringData("NETWORK ");
+ case kQuery: return createStringData("QUERY ");
+ case kReplication: return createStringData("REPLSETS");
+ case kSharding: return createStringData("SHARDING");
+ case kStorage: return createStringData("STORAGE ");
+ case kJournaling: return createStringData("JOURNAL ");
+ case kWrites: return createStringData("WRITES ");
+ case kNumLogComponents: return createStringData("TOTAL ");
+ // No default. Compiler should complain if there's a log component that's not handled.
+ }
+ invariant(false);
+ }
+
+ std::ostream& operator<<(std::ostream& os, LogComponent component) {
+ return os << component.getNameForLog();
+ }
+
} // logger
} // mongo
diff --git a/src/mongo/logger/log_component.h b/src/mongo/logger/log_component.h
index 01cf100d725..0fcd0c3e95d 100644
--- a/src/mongo/logger/log_component.h
+++ b/src/mongo/logger/log_component.h
@@ -27,8 +27,11 @@
#pragma once
+#include <iosfwd>
#include <string>
+#include "mongo/base/string_data.h"
+
namespace mongo {
namespace logger {
@@ -66,6 +69,11 @@ namespace logger {
LogComponent parent() const;
/**
+ * Returns short name as a StringData.
+ */
+ StringData toStringData() const;
+
+ /**
* Returns short name of log component.
* Used to generate server parameter names in the format "logLevel_<component short name>".
*/
@@ -78,9 +86,18 @@ namespace logger {
*/
std::string getDottedName() const;
+ /**
+ * Returns name suitable for inclusion in formatted log message.
+ * This is derived from upper-casing the short name with some padding to
+ * fit into a fixed length field.
+ */
+ StringData getNameForLog() const;
+
private:
Value _value;
};
+ std::ostream& operator<<(std::ostream& os, LogComponent component);
+
} // namespace logger
} // namespace mongo
diff --git a/src/mongo/logger/log_severity.cpp b/src/mongo/logger/log_severity.cpp
index ca60f7cdab9..576aab14cee 100644
--- a/src/mongo/logger/log_severity.cpp
+++ b/src/mongo/logger/log_severity.cpp
@@ -59,6 +59,26 @@ namespace {
return StringData(unknownSeverityString, StringData::LiteralTag());
}
+ char LogSeverity::toChar() const {
+ if (_severity > 0)
+ return 'D';
+ // 'S' might be confused with "Success"
+ // Return 'F' to imply Fatal instead.
+ if (*this == LogSeverity::Severe())
+ return 'F';
+ if (*this == LogSeverity::Error())
+ return 'E';
+ if (*this == LogSeverity::Warning())
+ return 'W';
+ if (*this == LogSeverity::Info())
+ return 'I';
+ if (*this == LogSeverity::Log())
+ return 'I';
+ // Should not reach here - returning 'U' for Unknown severity
+ // to be consistent with toStringData().
+ return 'U';
+ }
+
std::ostream& operator<<(std::ostream& os, LogSeverity severity) {
return os << severity.toStringData();
}
diff --git a/src/mongo/logger/log_severity.h b/src/mongo/logger/log_severity.h
index 388f7038d26..3857ebf4edf 100644
--- a/src/mongo/logger/log_severity.h
+++ b/src/mongo/logger/log_severity.h
@@ -89,6 +89,14 @@ namespace logger {
*/
StringData toStringData() const;
+ /**
+ * Returns a single capital letter naming this severity level.
+ * Equivalent to upper-case of first letter of toStringData() result.
+ *
+ * Not all levels are uniquely named.
+ */
+ char toChar() const;
+
//
// Comparison operations.
//
diff --git a/src/mongo/logger/log_test.cpp b/src/mongo/logger/log_test.cpp
index 26bd47cc51d..0837b51b753 100644
--- a/src/mongo/logger/log_test.cpp
+++ b/src/mongo/logger/log_test.cpp
@@ -43,6 +43,7 @@
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/log.h"
+#include "mongo/util/mongoutils/str.h"
using namespace mongo::logger;
@@ -51,6 +52,7 @@ namespace {
// TODO(schwerin): Have logger write to a different log from the global log, so that tests can
// redirect their global log output for examination.
+ template <typename MessageEventEncoder>
class LogTest : public unittest::Test {
friend class LogTestAppender;
public:
@@ -84,13 +86,16 @@ namespace {
private:
LogTest *_ltest;
- MessageEventUnadornedEncoder _encoder;
+ MessageEventEncoder _encoder;
};
MessageLogDomain::AppenderHandle _appenderHandle;
};
- TEST_F(LogTest, logContext) {
+ typedef LogTest<MessageEventDetailsEncoder> LogTestDetailsEncoder;
+ typedef LogTest<MessageEventUnadornedEncoder> LogTestUnadornedEncoder;
+
+ TEST_F(LogTestUnadornedEncoder, logContext) {
logContext("WHA!");
ASSERT_GREATER_THAN(_logLines.size(), 1U);
ASSERT_NOT_EQUALS(_logLines[0].find("WHA!"), std::string::npos);
@@ -117,7 +122,7 @@ namespace {
};
/** Simple tests for detaching appenders. */
- TEST_F(LogTest, DetachAppender) {
+ TEST_F(LogTestUnadornedEncoder, DetachAppender) {
MessageLogDomain::AppenderAutoPtr countAppender(new CountAppender);
MessageLogDomain domain;
@@ -146,7 +151,7 @@ namespace {
// Tests that logging while in the midst of logging produces two distinct log messages, with the
// inner log message appearing before the outer.
- TEST_F(LogTest, LogstreamBuilderReentrance) {
+ TEST_F(LogTestUnadornedEncoder, LogstreamBuilderReentrance) {
log() << "Logging A() -- " << A() << " -- done!" << std::endl;
ASSERT_EQUALS(2U, _logLines.size());
ASSERT_EQUALS(std::string("Golly!\n"), _logLines[0]);
@@ -172,7 +177,7 @@ namespace {
// No log component declared at file scope.
// Component severity configuration:
// LogComponent::kDefault: 2
- TEST_F(LogTest, MongoLogMacroNoFileScopeLogComponent) {
+ TEST_F(LogTestUnadornedEncoder, MongoLogMacroNoFileScopeLogComponent) {
globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(2));
LOG(2) << "This is logged";
@@ -211,7 +216,7 @@ namespace {
// Set MONGO_LOG's default component to componentB.
MONGO_LOG_DEFAULT_COMPONENT_FILE(componentB);
- TEST_F(LogTest, MongoLogMacroNamespaceScopeLogComponentDeclared) {
+ TEST_F(LogTestUnadornedEncoder, MongoLogMacroNamespaceScopeLogComponentDeclared) {
globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(1));
globalLogDomain()->setMinimumLoggedSeverity(componentB,
LogSeverity::Debug(2));
@@ -231,7 +236,7 @@ namespace {
// Component severity configuration:
// LogComponent::kDefault: 1
// componentA: 2
- TEST_F(LogTest, MongoLogMacroFunctionScopeLogComponentDeclared) {
+ TEST_F(LogTestUnadornedEncoder, MongoLogMacroFunctionScopeLogComponentDeclared) {
globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(1));
globalLogDomain()->setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2));
@@ -322,7 +327,7 @@ namespace {
// should be written to the log domain.
//
- TEST_F(LogTest, LogComponentSettingsMinimumLogSeverity) {
+ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsMinimumLogSeverity) {
LogComponentSettings settings;
ASSERT_TRUE(settings.hasMinimumLogSeverity(LogComponent::kDefault));
ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) == LogSeverity::Log());
@@ -358,7 +363,7 @@ namespace {
}
// Test for shouldLog() when the minimum logged severity is set only for LogComponent::kDefault.
- TEST_F(LogTest, LogComponentSettingsShouldLogDefaultLogComponentOnly) {
+ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogDefaultLogComponentOnly) {
LogComponentSettings settings;
// Initial log severity for LogComponent::kDefault is Log().
@@ -390,7 +395,7 @@ namespace {
// Minimum severity levels:
// LogComponent::kDefault: 1
// componentA: 2
- TEST_F(LogTest, LogComponentSettingsShouldLogSingleComponent) {
+ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogSingleComponent) {
LogComponentSettings settings;
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
@@ -415,7 +420,7 @@ namespace {
// LogComponent::kDefault: 1
// componentA: 2
// componentB: 0
- TEST_F(LogTest, LogComponentSettingsShouldLogMultipleComponentsConfigured) {
+ TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogMultipleComponentsConfigured) {
LogComponentSettings settings;
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
@@ -442,7 +447,7 @@ namespace {
}
// Log component hierarchy.
- TEST_F(LogTest, LogComponentHierarchy) {
+ TEST_F(LogTestUnadornedEncoder, LogComponentHierarchy) {
// Parent component is not meaningful for kDefault and kNumLogComponents.
ASSERT_EQUALS(LogComponent::kNumLogComponents,
LogComponent(LogComponent::kDefault).parent());
@@ -470,7 +475,7 @@ namespace {
}
// Dotted name of component includes names of ancestors.
- TEST_F(LogTest, LogComponentDottedName) {
+ TEST_F(LogTestUnadornedEncoder, LogComponentDottedName) {
// Default -> ComponentD -> ComponentE
ASSERT_EQUALS(componentDefault.getShortName(),
LogComponent(LogComponent::kDefault).getDottedName());
@@ -479,5 +484,111 @@ namespace {
componentE.getDottedName());
}
+ // Log names of all components should have the same length.
+ TEST_F(LogTestUnadornedEncoder, LogComponentNameForLog) {
+ size_t defaultNameForLogLength = componentDefault.getNameForLog().toString().length();
+ ASSERT_NOT_EQUALS(0U, defaultNameForLogLength);
+ for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
+ LogComponent component = static_cast<LogComponent::Value>(i);
+ ASSERT_EQUALS(defaultNameForLogLength, component.getNameForLog().toString().length());
+ }
+ }
+
+ /**
+ * Verifies that the encoded log line contains string.
+ */
+ void testEncodedLogLine(const MessageEventEphemeral& event,
+ const std::string& expectedSubstring) {
+ MessageEventDetailsEncoder encoder;
+ std::ostringstream os;
+ ASSERT_TRUE(encoder.encode(event, os));
+ std::string s = os.str();
+ if (s.find(expectedSubstring) == std::string::npos) {
+ FAIL(str::stream() << "encoded log line does not contain substring \""
+ << expectedSubstring << "\". log line: " << s);
+ }
+ }
+
+ // Log severity should always be logged as a single capital letter.
+ TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogSeverity) {
+ Date_t d(curTimeMillis64());
+ StringData ctx("WHAT", StringData::LiteralTag());
+ StringData msg("HUH", StringData::LiteralTag());
+ // Severe is indicated by (F)atal.
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Severe(), ctx, msg), " F ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Error(), ctx, msg), " E ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Warning(), ctx, msg), " W ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Info(), ctx, msg), " I ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Log(), ctx, msg), " I ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(0), ctx, msg), " I ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(1), ctx, msg), " D ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(2), ctx, msg), " D ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(3), ctx, msg), " D ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(4), ctx, msg), " D ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(5), ctx, msg), " D ");
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(100), ctx, msg), " D ");
+ // Unknown severity.
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Severe().moreSevere(), ctx, msg),
+ " U ");
+ }
+
+ // Non-default log component short name should always be logged.
+ TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogComponent) {
+ Date_t d(curTimeMillis64());
+ StringData ctx("WHAT", StringData::LiteralTag());
+ StringData msg("HUH", StringData::LiteralTag());
+ for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
+ LogComponent component = static_cast<LogComponent::Value>(i);
+ testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Info(), component, ctx, msg),
+ str::stream() << " I " << component.getNameForLog() << " [");
+ }
+ }
+
+ // Tests pass through of log component:
+ // log macros -> LogStreamBuilder -> MessageEventEphemeral -> MessageEventDetailsEncoder
+ TEST_F(LogTestDetailsEncoder, ) {
+ globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Log());
+
+ // Set MONGO_LOG's default component to componentA.
+ MONGO_LOG_DEFAULT_COMPONENT_LOCAL(componentA);
+
+ // LOG - MongoLogDefaultComponent (set to componentA) should appear in log line.
+ LOG(0) << "This is logged";
+ ASSERT_EQUALS(1U, _logLines.size());
+ ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()),
+ std::string::npos);
+
+ // Default log component short name should not appear in detailed log line.
+ _logLines.clear();
+ MONGO_LOG_COMPONENT(0, componentDefault) << "This is logged";
+ ASSERT_EQUALS(1U, _logLines.size());
+ ASSERT_NOT_EQUALS(_logLines[0].find(componentDefault.getNameForLog().toString()),
+ std::string::npos);
+
+ // Non-default log component short name should appear in detailed log line.
+ _logLines.clear();
+ MONGO_LOG_COMPONENT(0, componentA) << "This is logged";
+ ASSERT_EQUALS(1U, _logLines.size());
+ ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()),
+ std::string::npos);
+
+ // MONGO_LOG_COMPONENT2 - only the first component is sent to LogStreamBuilder.
+ _logLines.clear();
+ MONGO_LOG_COMPONENT2(0, componentA, componentB) << "This is logged";
+ ASSERT_EQUALS(1U, _logLines.size());
+ ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()),
+ std::string::npos);
+ ASSERT_EQUALS(_logLines[0].find(componentB.getNameForLog().toString()), std::string::npos);
+
+ // MONGO_LOG_COMPONENT3 - only the first component is sent to LogStreamBuilder.
+ _logLines.clear();
+ MONGO_LOG_COMPONENT3(0, componentA, componentB, componentC) << "This is logged";
+ ASSERT_EQUALS(1U, _logLines.size());
+ ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()),
+ std::string::npos);
+ ASSERT_EQUALS(_logLines[0].find(componentB.getNameForLog().toString()), std::string::npos);
+ ASSERT_EQUALS(_logLines[0].find(componentC.getNameForLog().toString()), std::string::npos);
+ }
+
} // namespace
} // namespace mongo
diff --git a/src/mongo/logger/logstream_builder.cpp b/src/mongo/logger/logstream_builder.cpp
index f37861d1143..348d6acbcba 100644
--- a/src/mongo/logger/logstream_builder.cpp
+++ b/src/mongo/logger/logstream_builder.cpp
@@ -70,6 +70,19 @@ namespace logger {
: _domain(domain),
_contextName(contextName),
_severity(severity),
+ _component(LogComponent::kDefault),
+ _os(NULL),
+ _tee(NULL) {
+ }
+
+ LogstreamBuilder::LogstreamBuilder(MessageLogDomain* domain,
+ const std::string& contextName,
+ LogSeverity severity,
+ LogComponent component)
+ : _domain(domain),
+ _contextName(contextName),
+ _severity(severity),
+ _component(component),
_os(NULL),
_tee(NULL) {
}
@@ -80,6 +93,7 @@ namespace logger {
: _domain(domain),
_contextName(contextName),
_severity(labeledLevel),
+ _component(LogComponent::kDefault),
_os(NULL),
_tee(NULL) {
@@ -90,6 +104,7 @@ namespace logger {
: _domain(other._domain),
_contextName(other._contextName),
_severity(other._severity),
+ _component(other._component),
_baseMessage(other._baseMessage),
_os(NULL),
_tee(NULL) {
@@ -103,7 +118,8 @@ namespace logger {
if (_os) {
if ( !_baseMessage.empty() ) _baseMessage.push_back(' ');
_baseMessage += _os->str();
- MessageEventEphemeral message(curTimeMillis64(), _severity, _contextName, _baseMessage);
+ MessageEventEphemeral message(curTimeMillis64(), _severity, _component, _contextName,
+ _baseMessage);
_domain->append(message);
if (_tee) {
_os->str("");
diff --git a/src/mongo/logger/logstream_builder.h b/src/mongo/logger/logstream_builder.h
index f03af002339..33360ad9a5b 100644
--- a/src/mongo/logger/logstream_builder.h
+++ b/src/mongo/logger/logstream_builder.h
@@ -34,6 +34,7 @@
#include "mongo/client/export_macros.h"
#include "mongo/logger/labeled_level.h"
+#include "mongo/logger/log_component.h"
#include "mongo/logger/log_severity.h"
#include "mongo/logger/message_log_domain.h"
#include "mongo/util/exit_code.h"
@@ -56,13 +57,25 @@ namespace logger {
* Construct a LogstreamBuilder that writes to "domain" on destruction.
*
* "contextName" is a short name of the thread or other context.
- * "severity" is the logging priority/severity of the message.
+ * "severity" is the logging severity of the message.
*/
LogstreamBuilder(MessageLogDomain* domain,
const std::string& contextName,
LogSeverity severity);
/**
+ * Construct a LogstreamBuilder that writes to "domain" on destruction.
+ *
+ * "contextName" is a short name of the thread or other context.
+ * "severity" is the logging severity of the message.
+ * "component" is the primary log component of the message.
+ */
+ LogstreamBuilder(MessageLogDomain* domain,
+ const std::string& contextName,
+ LogSeverity severity,
+ LogComponent component);
+
+ /**
* Deprecated.
*/
LogstreamBuilder(MessageLogDomain* domain,
@@ -142,6 +155,7 @@ namespace logger {
MessageLogDomain* _domain;
std::string _contextName;
LogSeverity _severity;
+ LogComponent _component;
std::string _baseMessage;
std::ostringstream* _os;
Tee* _tee;
diff --git a/src/mongo/logger/message_event.h b/src/mongo/logger/message_event.h
index 0aeb283953f..b38e792dcd1 100644
--- a/src/mongo/logger/message_event.h
+++ b/src/mongo/logger/message_event.h
@@ -28,6 +28,7 @@
#pragma once
#include "mongo/base/string_data.h"
+#include "mongo/logger/log_component.h"
#include "mongo/logger/log_severity.h"
#include "mongo/platform/cstdint.h"
#include "mongo/util/time_support.h"
@@ -50,17 +51,32 @@ namespace logger {
StringData message) :
_date(date),
_severity(severity),
+ _component(LogComponent::kDefault),
+ _contextName(contextName),
+ _message(message) {}
+
+ MessageEventEphemeral(
+ Date_t date,
+ LogSeverity severity,
+ LogComponent component,
+ StringData contextName,
+ StringData message) :
+ _date(date),
+ _severity(severity),
+ _component(component),
_contextName(contextName),
_message(message) {}
uint64_t getDate() const { return _date; }
LogSeverity getSeverity() const { return _severity; }
+ LogComponent getComponent() const { return _component; }
StringData getContextName() const { return _contextName; }
StringData getMessage() const { return _message; }
private:
Date_t _date;
LogSeverity _severity;
+ LogComponent _component;
StringData _contextName;
StringData _message;
};
diff --git a/src/mongo/logger/message_event_utf8_encoder.cpp b/src/mongo/logger/message_event_utf8_encoder.cpp
index 5a49b555afc..f73f46a8488 100644
--- a/src/mongo/logger/message_event_utf8_encoder.cpp
+++ b/src/mongo/logger/message_event_utf8_encoder.cpp
@@ -54,16 +54,19 @@ namespace logger {
_dateFormatter(os, event.getDate());
os << ' ';
+
+ os << event.getSeverity().toChar();
+ os << ' ';
+
+ LogComponent component = event.getComponent();
+ os << component;
+ os << ' ';
+
StringData contextName = event.getContextName();
if (!contextName.empty()) {
os << '[' << contextName << "] ";
}
- LogSeverity severity = event.getSeverity();
- if (severity >= LogSeverity::Info()) {
- os << severity << ": ";
- }
-
StringData msg = event.getMessage();
if (msg.size() > maxLogLine) {
os << "warning: log line attempted (" << msg.size() / 1024 << "k) over max size (" <<