- Reference >
- Database Commands >
- Diagnostic Commands >
- getLog
getLog¶
-
getLog
¶ getLog
is an administrative command that returns the most recent 1024 loggedmongod
events.getLog
does not read log data from themongod
log file. It instead reads data from a RAM cache of loggedmongod
events. To rungetLog
, use thedb.adminCommand()
method.Starting in MongoDB 4.4,
getLog
returns log data in escaped Relaxed Extended JSON v2.0 format. Previously, log data was returned as plaintext.
Syntax¶
The getLog
command has the following syntax:
Command Fields¶
The possible values for getLog
are:
Value | Description |
---|---|
* |
Returns a list of the available values to the
getLog command. |
global |
Returns the combined output of all recent log entries. |
startupWarnings |
Returns log entries 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. |
Output¶
If specified *
, then the command returns a document with the
names of the other acceptable values.
Otherwise, the command returns a document that includes the following fields:
totalLinesWritten
field that contains the number of log eventslog
field that contains an array of log events- A
db.adminCommand()
response document, containing status and timestamp information.
Behavior¶
Line Truncation¶
Starting in MongoDB 4.2, getLog
truncates any event
that contains more than 1024 characters. In earlier versions,
getLog
truncates after 512 characters.
Character Escaping¶
Starting in MongoDB 4.4, getLog
returns log data in
escaped Relaxed Extended JSON v2.0 format, using the following
escape sequences to render log output as valid JSON:
Character Represented | Escape Sequence |
---|---|
Quotation Mark (" ) |
\" |
Backslash (\ ) |
\\ |
Backspace (0x08 ) |
\b |
Formfeed (0x0C ) |
\f |
Newline (0x0A ) |
\n |
Carriage return (0x0D ) |
\r |
Horizontal tab (0x09 ) |
\t |
Control characters not listed above are escaped with \uXXXX
where
“XXXX” is the unicode codepoint in hexadecimal. Bytes with invalid
UTF-8 encoding are replaced with the unicode replacement character
represented by \ufffd
.