Docs Home → Develop Applications → MongoDB Manual
db.setLogLevel()![](/docs/v5.3/assets/link.svg)
On this page
Definition![](/docs/v5.3/assets/link.svg)
db.setLogLevel()
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
to5
:0
is the MongoDB's default log verbosity level, to include Informational messages.1
to5
increases the verbosity level to include Debug messages.
To inherit the verbosity level of the component's parent, you can also specify
-1
.component
stringOptional. The name of the component for which to specify the log verbosity level. The component name corresponds to the
<name>
from the correspondingsystemLog.component.<name>.verbosity
setting:Omit to specify the default verbosity level for all components.
Behavior![](/docs/v5.3/assets/link.svg)
db.setLogLevel()
sets a single verbosity level. To set
multiple verbosity levels in a single operation, use either the
setParameter
command to set the
logComponentVerbosity
parameter. You can also specify the
verbosity settings in the configuration file. See
Configure 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 previous
versions, MongoDB log messages only specified D
for Debug level.
Examples![](/docs/v5.3/assets/link.svg)
Set Default Verbosity Level![](/docs/v5.3/assets/link.svg)
Omit the <component>
parameter to set the default verbosity for all
components; i.e. the systemLog.verbosity
setting. The
operation sets the default verbosity to 1
:
db.setLogLevel(1)
Set Verbosity Level for a Component![](/docs/v5.3/assets/link.svg)
Specify the <component>
parameter to set the verbosity for the
component. The following operation updates the
systemLog.component.storage.journal.verbosity
to 2
:
db.setLogLevel(2, "storage.journal" )