Navigation

getLog

On this page

getLog

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>, txnNumber: <long>, lsid: { id: <UUID> } }
Field Type Description
getLog String

Log filter. Possible values for getLog are:

  • "*" to return the supported filters for getLog.
  • "global" to return the combined output of all recent log entries.
  • "rs" to return recent notices related to replica set activity if the mongod is part of a replica set.
  • "startupWarnings" to return 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..
txnNumber 64-bit integer/long

Optional.

A strictly increasing non-negative number that uniquely identifies the command in the command’s session.

If specified, the command must also include the lsid option.

New in version 3.6.

lsid Document

Optional.

The document that specifies the unique id of the session associated with the command. If the txnNumber is specified, the lsid is required.

Tip

The mongo shell and the drivers provide helpers to start the session and set the lsid for the commands.

New in version 3.6.

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

Behavior

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

getLog truncates any event that contains more than 512 characters.

Examples

Retrieve Available Log Filters

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

db.getSiblingDB("admin").runCommand( { 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.getSiblingDB("admin").runCommand( { getLog : "global" } )

The operation returns a document similar to the following:

{
   "totalLinesWritten" : <int>,
      "log" : [
      "2017-07-11T12:24:46.094-0400 I CONTROL  [initandlisten] MongoDB starting : pid=67001 port=27017 dbpath=./ 64-bit host=<host>",
      "2017-07-11T12:24:46.094-0400 I CONTROL  [initandlisten] db version v3.4.4",
      "2017-07-11T12:24:46.096-0400 I -        [initandlisten] Detected data files in ./ created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.",
      "2017-07-11T12:24:46.096-0400 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),",
      "2017-07-11T12:24:47.099-0400 I NETWORK  [thread1] waiting for connections on port 27017",
      "2017-07-11T12:57:42.517-0400 I NETWORK  [thread1] connection accepted from 127.0.0.1:55291 #1 (1 connection now open)",
      "2017-07-11T12:57:42.518-0400 I NETWORK  [conn1] received client metadata from 127.0.0.1:55291 conn1: { driver: { name: \"PyMongo\", version: \"3.4.0\" }, os: { type: \"Darwin\", name: \"Darwin\", architecture: \"x86_64\", version: \"10.11.6\" }, platform: \"CPython 3.5.1.final.0\" }",
   ],
   "ok" : 1
}

The highlighted line was truncated, as it exceeded 512 characters.

←   getCmdLineOpts hostInfo  →