db.setLogLevel()

On this page本页内容

Definition定义

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:采用以下参数:

Parameter参数Type类型Description描述
levelint

The log verbosity level.日志详细级别。

The verbosity level can range from 0 to 5:详细级别可以从05

  • 0 is the MongoDB's default log verbosity level, to include Informational messages.是MongoDB的默认日志详细级别,包括信息消息。
  • 1 to 5 increases the verbosity level to include Debug messages.15将增加详细级别以包括调试消息。

To inherit the verbosity level of the component's parent, you can also specify -1.要继承组件父级的详细级别,还可以指定-1

componentstring

Optional. 可选。The name of the component for which to specify the log verbosity level. 要为其指定日志详细级别的组件的名称。The component name corresponds to the <name> from the corresponding systemLog.component.<name>.verbosity setting:组件名称对应于相应systemLog.component.<name>.verbosity设置中的<name>

Omit to specify the default verbosity level for all components.省略以指定所有组件的默认详细级别。

Behavior行为

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. 要在单个操作中设置多个详细级别,请使用setParameter命令设置logComponentVerbosity参数。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. 从4.2版开始,MongoDB在日志消息中包含调试详细级别(1-5)。For example, if the verbosity level is 2, MongoDB logs D2. 例如,如果详细级别为2,则MongoDB将记录D2In previous versions, MongoDB log messages only specified D for Debug level.在以前的版本中,MongoDB日志消息仅将调试级别指定为D

Examples示例

Set Default Verbosity Level设置默认详细级别

Omit the <component> parameter to set the default verbosity for all components; i.e. the systemLog.verbosity setting. 省略<component>参数以设置所有组件的默认详细程度;即systemLog.verbosity设置。The operation 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 the component. 指定<component>参数以设置组件的详细程度。The following operation updates the systemLog.component.storage.journal.verbosity to 2:以下操作将systemLog.component.storage.journal.verbosity更新为2

db.setLogLevel(2, "storage.journal" )
←  db.serverStatus()db.setProfilingLevel() →