db.setLogLevel()
Definition
New in version 3.0.
Sets a single verbosity level for log messages.
db.setLogLevel()
has the following form:
- db.setLogLevel(<level>, <component>)
db.setLogLevel()
takes the following parameters:
ParameterTypeDescriptionlevel
intThe log verbosity level.
The verbosity level can range from 0
to 5
:
0
is the MongoDB’s default log verbosity level, to includeInformational messages.1
to5
increases the verbosity level to includeDebug messages.To inherit the verbosity level of the component’s parent, you canalso specify-1
.component
stringOptional. The name of the component for which to specify the log verbositylevel. The component name corresponds to the<name>
from thecorrespondingsystemLog.component.<name>.verbosity
setting:command
control
ftdc
geo
index
network
query
replication
replication.election
replication.heartbeats
replication.initialSync
replication.rollback
recovery
sharding
storage
storage.journal
transaction
write
Omit to specify the default verbosity level for all components.
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
:
- 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
:
- db.setLogLevel(2, "storage.journal" )