getLog

The getLog command has the following syntax:

  1. { getLog: <value> }

The possible values for getLog are:

  • global - returns the combined output of all recent logentries.
  • rs - if the mongod is part of a replicaset, getLog returns recent notices related toreplica set activity.
  • startupWarnings - returns logs that may contain errorsor warnings from MongoDB’s log from when the current processstarted. If mongod started without warnings, thisfilter may return an empty array.

Returns:A document that contains an array of log events as log and the numberof log events as totalLinesWritten.

Behavior

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

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

Examples

Retrieve Available Log Filters

The following operation returns the available log filters for passing togetLog

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

The operation returns the following document:

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

Retrieve Recent Events from Log

The following operation retrieves the most recent global events for themongod

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

The operation returns a document similar to the following:

  1. {
  2. "totalLinesWritten" : <num>,
  3. "log" : [
  4. "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",
  5. "2018-12-05T12:00:51.652-0500 I CONTROL [initandlisten] db version v4.2.0",
  6. "2018-12-05T12:00:51.653-0500 I CONTROL [initandlisten] git version: 322fcf0ee10ea6e27360cf6699e9ff98fb907ef6",
  7. "2018-12-05T12:00:51.654-0500 I CONTROL [initandlisten] allocator: system",
  8. "2018-12-05T12:00:51.654-0500 I CONTROL [initandlisten] modules: enterprise ",
  9. "2018-12-05T12:00:51.655-0500 I CONTROL [initandlisten] build environment:",
  10. "2018-12-05T12:00:51.656-0500 I CONTROL [initandlisten] distarch: x86_64",
  11. "2018-12-05T12:00:51.657-0500 I CONTROL [initandlisten] target_arch: x86_64",
  12.  
  13. ...
  14.  
  15. "2018-12-05T12:00:57.151-0500 I INITSYNC [replication-0] CollectionCloner ns:test.hugeindex finished cloning with status: OK",
  16. "2018-12-05T12:00:57.198-0500 I INITSYNC [replication-0] Finished cloning data: OK. Beginning oplog replay.",
  17. "2018-12-05T12:00:57.200-0500 I INITSYNC [replication-1] No need to apply operations. (currently at { : Timestamp(1544029250, 1) })",
  18. "2018-12-05T12:00:57.201-0500 I SHARDING [replication-0] Marking collection local.temp_oplog_buffer as collection version: <unsharded>",
  19. "2018-12-05T12:00:57.203-0500 I SHARDING [replication-0] Marking collection local.replset.oplogTruncateAfterPoint as collection version: <unsharded>",
  20. "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]",
  21. "2018-12-05T12:00:57.205-0500 I INITSYNC [replication-0] Initial sync attempt finishing up.",
  22. "2018-12-05T12:00:57.206-0500 I INITSYNC [replication-0] Initial Sync Attempt Statistics: { failedInitialSyncAttempts: 0, maxFailedInitialSyncAttempts: 10,
  23. initialSyncStart: new Date(1544029253464), initialSyncAttempts: [], fetchedMissingDocs: 0, appliedOps: 0, initialSyncOplogStart: Timestamp(1544029250, 1),
  24. initialSyncOplogEnd: Timestamp(1544029250, 1), databases: { databasesCloned: 5, admin: { collections: 4, clonedCollections: 4, start: new Date(1544029253838),
  25. end: new Date(1544029255537), elapsedMillis: 1699, admin.system.roles: { documentsToCopy: 4, documentsCopied: 4, indexes: 2, fetchedBatches: 1,
  26. start: new Date(1544029253840), end: new Date(1544029254110), elapsedMillis: 270, receivedBatches: 1 },
  27. admin.system.users: { documentsToCopy: 13, documentsCopied: 13, indexes: 2, fetchedBatches: 1, start: new Date(1544029254110),
  28. end: new Date(1544029254305), elapsedMillis: 195, receivedBatches: 1 }, admin.system.version: { documentsToCopy: 2, documentsCopied: 2, indexes: 1,
  29. fetchedBatches: 1, start: new D",
  30. "2018-12-05T12:00:57.208-0500 I STORAGE [replication-0] Finishing collection drop for local.temp_oplog_buffer (d547b85d-67cf-4721-86b1-1da5ee23845d).",
  31. "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)",
  32. "2018-12-05T12:00:57.246-0500 I INITSYNC [replication-0] initial sync done; took 3s.",
  33.  
  34. ],
  35. "ok" : 1
  36. }

The highlighted line was truncated as it exceeded 1024 characters.