diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2020-08-28 17:02:46 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-22 17:06:16 +0000 |
commit | cd8cce6dcb3d63bbf4bf882379540ed8b719dfc4 (patch) | |
tree | 2a4c78ef7ae4806bf46aba27b67470e941a5f25f /src/mongo/db/commands | |
parent | 51caad0e005e1a6dc1bd529cb809ba0d7d5eef0d (diff) | |
download | mongo-cd8cce6dcb3d63bbf4bf882379540ed8b719dfc4.tar.gz |
SERVER-50605 Add logMessage test-only command
(cherry picked from commit cbdf4deaa4ef4352750893ab0b4b276b86e3026f)
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/generic.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp index c1312768ee1..af647671660 100644 --- a/src/mongo/db/commands/generic.cpp +++ b/src/mongo/db/commands/generic.cpp @@ -500,6 +500,53 @@ public: MONGO_FP_DECLARE(crashOnShutdown); int* volatile illegalAddress; // NOLINT - used for fail point only +class CmdLogMessage : public BasicCommand { +public: + CmdLogMessage() : BasicCommand("logMessage") {} + + void help(stringstream& help) const final { + help << "Send a message to the server log"; + } + + bool supportsWriteConcern(const BSONObj& cmd) const final { + return false; + } + + bool slaveOk() const final { + return true; + } + + bool adminOnly() const final { + return true; + } + + void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) final { + out->push_back( + Privilege(ResourcePattern::forClusterResource(), ActionType::applicationMessage)); + } + + bool run(OperationContext* opCtx, + const std::string& ns, + const BSONObj& cmdObj, + BSONObjBuilder& result) final { + auto msgElem = cmdObj["logMessage"]; + uassert(ErrorCodes::BadValue, "logMessage must be a string", msgElem.type() == String); + + log() << "logMessage: " << msgElem.valueStringData(); + return true; + } +}; + +MONGO_INITIALIZER(RegisterCmdLogMessage)(InitializerContext* context) { + if (Command::testCommandsEnabled) { + // Leaked intentionally: a Command registers itself when constructed. + new CmdLogMessage(); + } + return Status::OK(); +} + } // namespace void CmdShutdown::addRequiredPrivileges(const std::string& dbname, |