This version of the documentation is archived and no longer supported.


On this page


getLog is an administrative command that returns the most recent 1024 logged mongod events. getLog does not read log data from the mongod log file. It instead reads data from a RAM cache of logged mongod events. To run getLog, use the db.runCommand( { command } ) method on the admin database.

The getLog command has the following syntax:

{ getLog: <value> }

The possible values for getLog are:

  • global - returns the combined output of all recent log entries.
  • rs - if the mongod is part of a replica set, getLog returns recent notices related to replica set activity.
  • startupWarnings - returns logs that may contain errors or warnings from MongoDB’s log from when the current process started. If mongod started without warnings, this filter may return an empty array.
Returns:A document that contains an array of log events as log and the number of log events as totalLinesWritten.


Specify * to getLog to return a list of available log filters for the mongod.

Starting in MongoDB 4.2, getLog truncates any event that contains more than 1024 characters. In earlier versions, getLog truncates after 512 characters.


Retrieve Available Log Filters

The following operation returns the available log filters for passing to getLog

db.adminCommand( { getLog: "*" } )

The operation returns the following document:

{ "names" : [ "global", "rs", "startupWarnings" ], "ok" : 1 }

Retrieve Recent Events from Log

The following operation retrieves the most recent global events for the mongod

db.adminCommand( { getLog : "global" } )

The operation returns a document similar to the following:

   "totalLinesWritten" : <num>,
   "log" : [
      "2018-12-05T12:00:51.651-0500 I CONTROL  [initandlisten] MongoDB starting : pid=51825 port=27019 dbpath=/data/Reporting Cluster Data/ShardA/Member00000-000000-1 64-bit host=kays-mac-mini.local",
      "2018-12-05T12:00:51.652-0500 I CONTROL  [initandlisten] db version v4.2.0",
      "2018-12-05T12:00:51.653-0500 I CONTROL  [initandlisten] git version: 322fcf0ee10ea6e27360cf6699e9ff98fb907ef6",
      "2018-12-05T12:00:51.654-0500 I CONTROL  [initandlisten] allocator: system",
      "2018-12-05T12:00:51.654-0500 I CONTROL  [initandlisten] modules: enterprise ",
      "2018-12-05T12:00:51.655-0500 I CONTROL  [initandlisten] build environment:",
      "2018-12-05T12:00:51.656-0500 I CONTROL  [initandlisten]     distarch: x86_64",
      "2018-12-05T12:00:51.657-0500 I CONTROL  [initandlisten]     target_arch: x86_64",


      "2018-12-05T12:00:57.151-0500 I INITSYNC [replication-0] CollectionCloner ns:test.hugeindex finished cloning with status: OK",
      "2018-12-05T12:00:57.198-0500 I INITSYNC [replication-0] Finished cloning data: OK. Beginning oplog replay.",
      "2018-12-05T12:00:57.200-0500 I INITSYNC [replication-1] No need to apply operations. (currently at { : Timestamp(1544029250, 1) })",
      "2018-12-05T12:00:57.201-0500 I SHARDING [replication-0] Marking collection local.temp_oplog_buffer as collection version: <unsharded>",
      "2018-12-05T12:00:57.203-0500 I SHARDING [replication-0] Marking collection local.replset.oplogTruncateAfterPoint as collection version: <unsharded>",
      "2018-12-05T12:00:57.204-0500 I INITSYNC [replication-0] Finished fetching oplog during initial sync: CallbackCanceled: error in fetcher batch callback: oplog fetcher is shutting down. Last fetched optime and hash: { ts: Timestamp(0, 0), t: -1 }[0]",
      "2018-12-05T12:00:57.205-0500 I INITSYNC [replication-0] Initial sync attempt finishing up.",
      "2018-12-05T12:00:57.206-0500 I INITSYNC [replication-0] Initial Sync Attempt Statistics: { failedInitialSyncAttempts: 0, maxFailedInitialSyncAttempts: 10,
initialSyncStart: new Date(1544029253464), initialSyncAttempts: [], fetchedMissingDocs: 0, appliedOps: 0, initialSyncOplogStart: Timestamp(1544029250, 1),
initialSyncOplogEnd: Timestamp(1544029250, 1), databases: { databasesCloned: 5, admin: { collections: 4, clonedCollections: 4, start: new Date(1544029253838),
end: new Date(1544029255537), elapsedMillis: 1699, admin.system.roles: { documentsToCopy: 4, documentsCopied: 4, indexes: 2, fetchedBatches: 1,
start: new Date(1544029253840), end: new Date(1544029254110), elapsedMillis: 270, receivedBatches: 1 },
admin.system.users: { documentsToCopy: 13, documentsCopied: 13, indexes: 2, fetchedBatches: 1, start: new Date(1544029254110),
end: new Date(1544029254305), elapsedMillis: 195, receivedBatches: 1 }, admin.system.version: { documentsToCopy: 2, documentsCopied: 2, indexes: 1,
fetchedBatches: 1, start: new D",
      "2018-12-05T12:00:57.208-0500 I STORAGE  [replication-0] Finishing collection drop for local.temp_oplog_buffer (d547b85d-67cf-4721-86b1-1da5ee23845d).",
      "2018-12-05T12:00:57.244-0500 I STORAGE  [replication-0] Triggering the first stable checkpoint. Initial Data: Timestamp(1544029250, 1) PrevStable: Timestamp(0, 0) CurrStable: Timestamp(1544029250, 1)",
      "2018-12-05T12:00:57.246-0500 I INITSYNC [replication-0] initial sync done; took 3s.",

   "ok" : 1

The highlighted line was truncated as it exceeded 1024 characters.

←   getCmdLineOpts hostInfo  →