getLog
getLog
getLog
is an administrative command that returns the mostrecent 1024 loggedmongod
events.getLog
_does not_read log data from themongod
log file. It instead reads datafrom a RAM cache of loggedmongod
events. To rungetLog
, use thedb.runCommand( { command } )
method on theadmin
database.
The getLog
command has the following syntax:
- { getLog: <value> }
The possible values for getLog
are:
global
- returns the combined output of all recent logentries.rs
- if themongod
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. Ifmongod
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
- 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 themongod
- 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.