db.setLogLevel()

Definition

  • db.setLogLevel()

New in version 3.0.

Sets a single verbosity level for log messages.

db.setLogLevel() has the following form:

  1. db.setLogLevel(<level>, <component>)

db.setLogLevel() takes the following parameters:

ParameterTypeDescriptionlevelintThe log verbosity level.

The verbosity level can range from 0 to 5:

Behavior

db.setLogLevel() sets a single verbosity level. To setmultiple verbosity levels in a single operation, use either thesetParameter command to set thelogComponentVerbosity parameter. You can also specify theverbosity settings in the configuration file. SeeConfigure Log Verbosity Levels for examples.

Note

Starting in version 4.2, MongoDB includes the Debug verbosity level(1-5) in the log messages. For example,if the verbosity level is 2, MongoDB logs D2. In previousversions, MongoDB log messages only specified D for Debug level.

Examples

Set Default Verbosity Level

Omit the <component> parameter to set the default verbosity for allcomponents; i.e. the systemLog.verbosity setting. Theoperation sets the default verbosity to 1:

  1. db.setLogLevel(1)

Set Verbosity Level for a Component

Specify the <component> parameter to set the verbosity for thecomponent. The following operation updates thesystemLog.component.storage.journal.verbosity to 2:

  1. db.setLogLevel(2, "storage.journal" )