From bab691491a8db3419dab5ecd79689d5357f1e0cc Mon Sep 17 00:00:00 2001 From: Gabriel Russell Date: Wed, 29 Apr 2020 17:30:06 -0400 Subject: SERVER-46933 reformat the json startupWarnings --- src/mongo/shell/utils.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 9ae58f3910c..d3a2e32e55f 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -862,6 +862,8 @@ shellHelper.show = function(what) { what = args[0]; args = args.splice(1); + var messageIndent = " "; + if (what == "profile") { if (db.system.profile.count() == 0) { print("db.system.profile is empty"); @@ -1013,10 +1015,27 @@ shellHelper.show = function(what) { if (res.log.length == 0) { return ""; } - print("Server has startup warnings: "); + print("---"); + print("The server generated these startup warnings when booting: "); for (var i = 0; i < res.log.length; i++) { - print(res.log[i]); + var logOut; + try { + var parsedLog = JSON.parse(res.log[i]); + var linePrefix = messageIndent + parsedLog.t["$date"] + ": "; + logOut = linePrefix + parsedLog.msg + "\n"; + if (parsedLog.attr) { + for (var attr in parsedLog.attr) { + logOut += linePrefix + messageIndent + attr + ": " + + parsedLog.attr[attr] + "\n"; + } + } + } catch (err) { + // err is intentionally unused here + logOut = res.log[i]; + } + print(logOut); } + print("---"); return ""; } else if (res.errmsg == "no such cmd: getLog") { // Don't print if the command is not available @@ -1089,15 +1108,19 @@ shellHelper.show = function(what) { print("---"); } else if (freemonStatus.state === 'undecided') { print( - "---\n" + + "---\n" + messageIndent + "Enable MongoDB's free cloud-based monitoring service, which will then receive and display\n" + + messageIndent + "metrics about your deployment (disk utilization, CPU, operation statistics, etc).\n" + - "\n" + + "\n" + messageIndent + "The monitoring data will be available on a MongoDB website with a unique URL accessible to you\n" + + messageIndent + "and anyone you share the URL with. MongoDB may use this information to make product\n" + + messageIndent + "improvements and to suggest MongoDB products and deployment options to you.\n" + - "\n" + + "\n" + messageIndent + "To enable free monitoring, run the following command: db.enableFreeMonitoring()\n" + + messageIndent + "To permanently disable this reminder, run the following command: db.disableFreeMonitoring()\n" + "---\n"); } -- cgit v1.2.1