summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-02-13 16:55:02 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-14 23:22:38 +0000
commit7a91c2823d5c0f94ad0d0e6bb5e830df0276da2a (patch)
treef16c5131af6c8059aee67c7d23cdfd03ae1defe2 /src
parent05feebc53d0ad88574cfba9bbc7640d2244f9756 (diff)
downloadmongo-7a91c2823d5c0f94ad0d0e6bb5e830df0276da2a.tar.gz
SERVER-45138 Add MONGO_CONFIG_JSON_LOG_DEFAULT define to use JSON logs by default
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/curop.cpp2
-rw-r--r--src/mongo/db/repl/oplog_applier_impl.cpp2
-rw-r--r--src/mongo/db/s/transaction_coordinator.cpp2
-rw-r--r--src/mongo/db/transaction_participant.cpp2
-rw-r--r--src/mongo/logv2/log_domain_global.cpp6
-rw-r--r--src/mongo/s/transaction_router.cpp2
-rw-r--r--src/mongo/shell/dbshell.cpp8
-rw-r--r--src/mongo/util/log.cpp8
-rw-r--r--src/mongo/util/log_global_settings.h2
9 files changed, 27 insertions, 7 deletions
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 6842bec55fa..385b53141d1 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -490,7 +490,7 @@ bool CurOp::completeAndLogOperation(OperationContext* opCtx,
_debug.prepareConflictDurationMillis =
duration_cast<Milliseconds>(prepareConflictDurationMicros);
- if (serverGlobalParams.logFormat == logv2::LogFormat::kJson) {
+ if (logV2IsJson(serverGlobalParams.logFormat)) {
logv2::DynamicAttributes attr;
_debug.report(opCtx, (lockerInfo ? &lockerInfo->stats : nullptr), &attr);
LOGV2(51803, "slow query", attr);
diff --git a/src/mongo/db/repl/oplog_applier_impl.cpp b/src/mongo/db/repl/oplog_applier_impl.cpp
index e801962d0df..6d9586b8f0c 100644
--- a/src/mongo/db/repl/oplog_applier_impl.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl.cpp
@@ -113,7 +113,7 @@ Status finishAndLogApply(OperationContext* opCtx,
Milliseconds(opDuration),
Milliseconds(serverGlobalParams.slowMS))
.first) {
- if (serverGlobalParams.logFormat == logv2::LogFormat::kJson) {
+ if (logV2IsJson(serverGlobalParams.logFormat)) {
logv2::DynamicAttributes attrs;
diff --git a/src/mongo/db/s/transaction_coordinator.cpp b/src/mongo/db/s/transaction_coordinator.cpp
index f3a6696db93..03c21e4ce5f 100644
--- a/src/mongo/db/s/transaction_coordinator.cpp
+++ b/src/mongo/db/s/transaction_coordinator.cpp
@@ -422,7 +422,7 @@ void TransactionCoordinator::_done(Status status) {
void TransactionCoordinator::_logSlowTwoPhaseCommit(
const txn::CoordinatorCommitDecision& decision) {
- if (serverGlobalParams.logFormat == logv2::LogFormat::kJson) {
+ if (logV2IsJson(serverGlobalParams.logFormat)) {
logv2::DynamicAttributes attrs;
BSONObjBuilder parametersBuilder;
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 26162528a7c..c8180467c20 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -1989,7 +1989,7 @@ void TransactionParticipant::Participant::_logSlowTransaction(
opDuration,
Milliseconds(serverGlobalParams.slowMS))
.first) {
- if (serverGlobalParams.logFormat == logv2::LogFormat::kJson) {
+ if (logV2IsJson(serverGlobalParams.logFormat)) {
logv2::DynamicAttributes attr;
_transactionInfoForLog(opCtx, lockStats, terminationCause, readConcernArgs, &attr);
LOGV2_OPTIONS(51802, {logv2::LogComponent::kTransaction}, "transaction", attr);
diff --git a/src/mongo/logv2/log_domain_global.cpp b/src/mongo/logv2/log_domain_global.cpp
index 2788cd8aca4..6b9603cc82f 100644
--- a/src/mongo/logv2/log_domain_global.cpp
+++ b/src/mongo/logv2/log_domain_global.cpp
@@ -29,6 +29,7 @@
#include "log_domain_global.h"
+#include "mongo/config.h"
#include "mongo/logv2/component_settings_filter.h"
#include "mongo/logv2/composite_backend.h"
#include "mongo/logv2/console.h"
@@ -174,11 +175,16 @@ Status LogDomainGlobal::Impl::configure(LogDomainGlobal::ConfigurationOptions co
};
switch (options.format) {
+#if !defined(MONGO_CONFIG_JSON_LOG_DEFAULT)
case LogFormat::kDefault:
+#endif
case LogFormat::kText:
setFormatters(
[&] { return TextFormatter(options.maxAttributeSizeKB, options.timestampFormat); });
break;
+#if defined(MONGO_CONFIG_JSON_LOG_DEFAULT)
+ case LogFormat::kDefault:
+#endif
case LogFormat::kJson:
setFormatters(
[&] { return JSONFormatter(options.maxAttributeSizeKB, options.timestampFormat); });
diff --git a/src/mongo/s/transaction_router.cpp b/src/mongo/s/transaction_router.cpp
index 2656c0b7b66..21d8d513009 100644
--- a/src/mongo/s/transaction_router.cpp
+++ b/src/mongo/s/transaction_router.cpp
@@ -1333,7 +1333,7 @@ BSONObj TransactionRouter::Router::_commitWithRecoveryToken(OperationContext* op
void TransactionRouter::Router::_logSlowTransaction(OperationContext* opCtx,
TerminationCause terminationCause) const {
- if (serverGlobalParams.logFormat == logv2::LogFormat::kJson) {
+ if (logV2IsJson(serverGlobalParams.logFormat)) {
logv2::DynamicAttributes attrs;
BSONObjBuilder parametersBuilder;
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index 992e8a2337d..f00f55b3c93 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -792,8 +792,12 @@ int _main(int argc, char* argv[], char** envp) {
auto consoleSink = boost::make_shared<boost::log::sinks::synchronous_sink<ShellBackend>>();
consoleSink->set_filter(logv2::ComponentSettingsFilter(lv2Manager.getGlobalDomain(),
lv2Manager.getGlobalSettings()));
- consoleSink->set_formatter(
- ShellFormatter(shellGlobalParams.logFormat == logv2::LogFormat::kJson));
+#if defined(MONGO_CONFIG_JSON_LOG_DEFAULT)
+ bool isJson = shellGlobalParams.logFormat != logv2::LogFormat::kText;
+#else
+ bool isJson = shellGlobalParams.logFormat == logv2::LogFormat::kJson;
+#endif
+ consoleSink->set_formatter(ShellFormatter(isJson));
consoleSink->locked_backend()->add_stream(
boost::shared_ptr<std::ostream>(&logv2::Console::out(), boost::null_deleter()));
diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp
index a60fd216972..41716f78015 100644
--- a/src/mongo/util/log.cpp
+++ b/src/mongo/util/log.cpp
@@ -66,6 +66,14 @@ bool logV2Enabled() {
return _logV2Enabled;
}
+bool logV2IsJson(logv2::LogFormat format) {
+ return format == logv2::LogFormat::kJson
+#if defined(MONGO_CONFIG_JSON_LOG_DEFAULT)
+ || format == logv2::LogFormat::kDefault
+#endif
+ ;
+}
+
void logV2Set(bool setting) {
_logV2Enabled = setting;
}
diff --git a/src/mongo/util/log_global_settings.h b/src/mongo/util/log_global_settings.h
index 79e3f177580..ef0a1c022dd 100644
--- a/src/mongo/util/log_global_settings.h
+++ b/src/mongo/util/log_global_settings.h
@@ -36,11 +36,13 @@
#include "mongo/logger/logger.h"
#include "mongo/logv2/log_component.h"
#include "mongo/logv2/log_component_settings.h"
+#include "mongo/logv2/log_format.h"
#include "mongo/logv2/log_manager.h"
namespace mongo {
bool logV2Enabled();
+bool logV2IsJson(logv2::LogFormat format);
void logV2Set(bool setting);
/**