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详细程度级别可以在0to5:0到5之间:0is the MongoDB's default log verbosity level, to include Informational messages.是MongoDB的默认日志详细级别,以包括信息消息。1to5increases the verbosity level to include Debug messages.1到5增加了详细级别以包括调试消息。
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 correspondingsystemLog.component.<name>.verbositysetting:systemLog.component.<name>.verbosity设置中的<name>:accessControlcommandcontrolftdcgeoindexnetworkqueryreplicationreplication.electionreplication.heartbeatsreplication.initialSyncreplication.rollbackrecoveryshardingstoragestorage.journaltransactionwrite
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.您也可以在配置文件中指定详细程度设置。有关示例,请参阅配置日志详细级别。
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 例如,如果详细级别为2,MongoDB将记录D2. D2。In previous versions, MongoDB log messages only specified 在以前的版本中,MongoDB日志消息只为调试级别指定了D for Debug level.D。
Examples实例
Set Default Verbosity Level设置默认详细级别
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:<component>参数以设置所有组件的默认详细程度;即systemLog.verbosity设置。该操作将默认详细程度设置为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" )