- Reference >
- Log Messages
Log Messages¶
On this page
Log Message Format (Console/Log File)¶
Starting in MongoDB 3.0, MongoDB includes the severity level and the component for each log message when output to the
console or a logfile (i.e. not to syslog [1]).
The log messages have the form:
For example:
| [1] | Syslog messages follow the standard syslog message format. Starting
in version 4.2, MongoDB includes the component in its log messages to syslog. |
Logging Slow Operations¶
Client operations appear in the log if their duration exceeds the slow operation threshold or when the log verbosity level is 1 or higher. [3] These log entries include the full command object associated with the operation.
Starting in MongoDB 4.2, the profiler entries and the diagnostic log messages (i.e. mongod/mongos log messages) for read/write operations include:
queryHashto help identify slow queries with the same query shape.planCacheKeyto provide more insight into the query plan cache for slow queries.
The following example output includes information about a slow aggregation operation:
Time Waiting for Shards Logged in remoteOpWaitMillis Field¶
New in version 4.2.10.
Starting in MongoDB 4.2.10, you can use the remoteOpWaitMillis log
field to obtain the wait time (in milliseconds) for results from
shards.
remoteOpWaitMillis is only logged:
- If you configure slow operations logging.
- On the shard or
mongosthat merges the results.
To determine if a merge operation or a shard issue is causing a slow
query, compare the durationMillis and remoteOpWaitMillis time
fields in the log. durationMillis is the total time the query took
to complete. Specifically:
- If
durationMillisis slightly longer thanremoteOpWaitMillis, then most of the time was spent waiting for a shard response. For example,durationMillisof 17 andremoteOpWaitMillisof 15. - If
durationMillisis significantly longer thanremoteOpWaitMillis, then most of the time was spent performing the merge. For example,durationMillisof 100 andremoteOpWaitMillisof 15.
Timestamp (Console/Log File)¶
When logging to the console or a logfile [2], the default
format for the <timestamp> is iso8601-local. To modify the
timestamp format, use the --timeStampFormat runtime option or the
systemLog.timeStampFormat setting.
| [2] | If logging to syslog, the syslog daemon generates timestamps
when it logs a message, not when MongoDB issues the message. This
can lead to misleading timestamps for log entries, especially when
the system is under heavy load. |
Severity Levels¶
The following table lists the severity levels associated with each log message:
| Level | Description |
|---|---|
F |
Fatal |
E |
Error |
W |
Warning |
I |
Informational, for Verbosity Level of 0 |
D[1-5] |
Debug, for All Verbosity Levels > Starting in version 4.2, MongoDB logs the debug verbosity
level. For example, if
verbosity level is 2, MongoDB logs In previous versions, MongoDB log messages only specified |
You can specify the verbosity level of various components to determine the amount of Informational and Debug messages MongoDB outputs. [3]
To set verbosity levels, see Configure Log Verbosity Levels.
Client Data¶
New in version 3.4.
Client application debugging and performance monitoring is easier
when you can clearly match server events with particular client
requests. With this in mind, recent MongoDB
drivers and client
applications (including the mongo shell) have the ability
to send identifying information at the time of connection to the
server. After the connection is established, the client does not send
the identifying information again unless the connection is dropped
and reestablished.
The exact fields included vary by client. Below is a sample client data document:
When secondary members of a replica set initiate a connection to a primary, they send similar data. A typical connection document is as follows:
For a complete description of client information and required fields, see the MongoDB Handshake specification.
Components¶
Log messages now include components, providing functional categorization of the messages:
-
ACCESS¶ Messages related to access control, such as authentication. To specify the log level for
ACCESScomponents, use thesystemLog.component.accessControl.verbositysetting.
-
COMMAND¶ Messages related to database commands, such as
count. To specify the log level forCOMMANDcomponents, use thesystemLog.component.command.verbositysetting.
-
CONTROL¶ Messages related to control activities, such as initialization. To specify the log level for
CONTROLcomponents, use thesystemLog.component.control.verbositysetting.
-
ELECTION¶ Messages related specifically to replica set elections. To specify the log level for
ELECTIONcomponents, set thesystemLog.component.replication.election.verbosityparameter.REPLis the parent component ofELECTION. IfsystemLog.component.replication.election.verbosityis unset, MongoDB uses theREPLverbosity level forELECTIONcomponents.
-
FTDC¶ New in version 3.2.
Messages related to the diagnostic data collection mechanism, such as server statistics and status messages. To specify the log level for
FTDCcomponents, use thesystemLog.component.ftdc.verbositysetting.
-
GEO¶ Messages related to the parsing of geospatial shapes, such as verifying the GeoJSON shapes. To specify the log level for
GEOcomponents, set thesystemLog.component.geo.verbosityparameter.
-
INDEX¶ Messages related to indexing operations, such as creating indexes. To specify the log level for
INDEXcomponents, set thesystemLog.component.index.verbosityparameter.
-
INITSYNC¶ Messages related to initial sync operation. To specify the log level for
INITSYNCcomponents, set thesystemLog.component.replication.initialSync.verbosityparameter.REPLis the parent component ofINITSYNC. IfsystemLog.component.replication.initialSync.verbosityis unset, MongoDB uses theREPLverbosity level forINITSYNCcomponents.
-
NETWORK¶ Messages related to network activities, such as accepting connections. To specify the log level for
NETWORKcomponents, set thesystemLog.component.network.verbosityparameter.
-
QUERY¶ Messages related to queries, including query planner activities. To specify the log level for
QUERYcomponents, set thesystemLog.component.query.verbosityparameter.
-
REPL¶ Messages related to replica sets, such as initial sync, heartbeats, steady state replication, and rollback. [3] To specify the log level for
REPLcomponents, set thesystemLog.component.replication.verbosityparameter.
-
REPL_HB¶ Messages related specifically to replica set heartbeats. To specify the log level for
REPL_HBcomponents, set thesystemLog.component.replication.heartbeats.verbosityparameter.REPLis the parent component ofREPL_HB. IfsystemLog.component.replication.heartbeats.verbosityis unset, MongoDB uses theREPLverbosity level forREPL_HBcomponents.
-
ROLLBACK¶ Messages related to rollback operations. To specify the log level for
ROLLBACKcomponents, set thesystemLog.component.replication.rollback.verbosityparameter.REPLis the parent component ofROLLBACK. IfsystemLog.component.replication.rollback.verbosityis unset, MongoDB uses theREPLverbosity level forROLLBACKcomponents.
-
SHARDING¶ Messages related to sharding activities, such as the startup of the
mongos. To specify the log level forSHARDINGcomponents, use thesystemLog.component.sharding.verbositysetting.
-
STORAGE¶ Messages related to storage activities, such as processes involved in the
fsynccommand. To specify the log level forSTORAGEcomponents, use thesystemLog.component.storage.verbositysetting.
-
RECOVERY¶ Messages related to recovery activities. To specify the log level for
RECOVERYcomponents, use thesystemLog.component.storage.recovery.verbositysetting.
-
JOURNAL¶ Messages related specifically to journaling activities. To specify the log level for
JOURNALcomponents, use thesystemLog.component.storage.journal.verbositysetting.STORAGEis the parent component ofJOURNAL. IfsystemLog.component.storage.journal.verbosityis unset, MongoDB uses theSTORAGEverbosity level forJOURNALcomponents.
-
TXN¶ Messages related to multi-document transactions. To specify the log level for
TXNcomponents, use thesystemLog.component.transaction.verbositysetting.
-
WRITE¶ Messages related to write operations, such as
updatecommands. To specify the log level forWRITEcomponents, use thesystemLog.component.write.verbositysetting.
-
-¶ Messages not associated with a named component. Unnamed components have the default log level specified in the
systemLog.verbositysetting. ThesystemLog.verbositysetting is the default setting for both named and unnamed components.
Verbosity Levels¶
View Current Log Verbosity Level¶
To view the current verbosity levels, use the
db.getLogComponents() method.
Configure Log Verbosity Levels¶
You can configure the verbosity level using: the
systemLog.verbosity and
systemLog.component.<name>.verbosity settings, the
logComponentVerbosity parameter; the
db.setLogLevel() method. [3]
systemLog Verbosity Settings¶
To configure the default log level for all components, use the
systemLog.verbosity setting. To configure the level of
specific components, use the systemLog.component.<name>.verbosity
settings.
For example, the following configuration sets the
systemLog.verbosity to 1, the
systemLog.component.query.verbosity to 2, the
systemLog.component.storage.verbosity to 2, and the
systemLog.component.storage.journal.verbosity to 1:
All components not specified in the configuration have the
systemLog.verbosity of 1.
logComponentVerbosity Parameter¶
To set the logComponentVerbosity parameter, pass a
document with the verbosity settings to change.
For example, the following sets the default verbosity level to 1, the query to 2, the storage to 2, and the
storage.journal to 1.
db.setLogLevel()¶
Use the db.setLogLevel() method to update a single component
log level. For a component, you can specify verbosity level of 0 to
5, or you can specify -1 to inherit the verbosity of the
parent. For example, the following sets the
systemLog.component.query.verbosity to its parent verbosity
(i.e. default verbosity):
| [3] | (1, 2, 3, 4) Starting in version 4.2 (also available starting in 4.0.6), secondary members of a replica set now
log oplog entries that take longer than the slow
operation threshold to apply. These slow oplog messages are logged
for the secondaries in the diagnostic log under the REPL component with the text applied
op: <oplog entry> took <num>ms. These slow oplog entries depend
only on the slow operation threshold. They do not depend on the log
levels (either at the system or component level), or the profiling
level, or the slow operation sample rate. The profiler does not
capture slow oplog entries. |