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.0是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>:
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
Important
This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
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 例如,如果详细程度为2,MongoDB会记录D2. In previous versions, MongoDB log messages only specified D for Debug level.D2。在以前的版本中,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. The operation sets the default verbosity to 1:<component>参数以设置所有组件的默认详细程度;即systemLog.verbosity(系统日志冗余度)设置。该操作将默认详细程度设置为1:
db.setLogLevel(1)
{
was: {
verbosity: 1,
accessControl: { verbosity: -1 },
assert: { verbosity: -1 },
command: { verbosity: -1 },
control: { verbosity: -1 },
executor: { verbosity: -1 },
geo: { verbosity: -1 },
globalIndex: { verbosity: -1 },
index: { verbosity: -1 },
network: {
verbosity: -1,
asio: { verbosity: -1 },
bridge: { verbosity: -1 },
connectionPool: { verbosity: -1 }
},
processHealth: { verbosity: -1 },
query: {
verbosity: -1,
optimizer: { verbosity: -1 },
ce: { verbosity: -1 }
},
queryStats: { verbosity: -1 },
replication: {
verbosity: -1,
election: { verbosity: -1 },
heartbeats: { verbosity: -1 },
initialSync: { verbosity: -1 },
rollback: { verbosity: -1 }
},
sharding: {
verbosity: -1,
rangeDeleter: { verbosity: -1 },
shardingCatalogRefresh: { verbosity: -1 },
migration: { verbosity: -1 },
reshard: { verbosity: -1 },
migrationPerf: { verbosity: -1 }
},
storage: {
verbosity: -1,
recovery: { verbosity: -1 },
journal: { verbosity: 2 },
wt: {
verbosity: -1,
wtBackup: { verbosity: -1 },
wtCheckpoint: { verbosity: -1 },
wtCompact: { verbosity: -1 },
wtEviction: { verbosity: -1 },
wtHS: { verbosity: -1 },
wtRecovery: { verbosity: -1 },
wtRTS: { verbosity: -1 },
wtSalvage: { verbosity: -1 },
wtTiered: { verbosity: -1 },
wtTimestamp: { verbosity: -1 },
wtTransaction: { verbosity: -1 },
wtVerify: { verbosity: -1 },
wtWriteLog: { verbosity: -1 }
}
},
write: { verbosity: -1 },
ftdc: { verbosity: -1 },
tracking: { verbosity: -1 },
transaction: { verbosity: -1 },
tenantMigration: { verbosity: -1 },
test: { verbosity: -1 },
resourceConsumption: { verbosity: -1 },
streams: { verbosity: -1 }
},
ok: 1
}
Set Verbosity Level for a Component设置组件的详细程度
Specify the 指定<component> parameter to set the verbosity for the component. The following operation updates the systemLog.component.storage.journal.verbosity to 2:<component>参数以设置组件的详细程度。以下操作将systemLog.component.storage.journal.verbosity更新为2:
db.setLogLevel(2, "storage.journal" )
{
was: {
verbosity: 1,
accessControl: { verbosity: -1 },
assert: { verbosity: -1 },
command: { verbosity: -1 },
control: { verbosity: -1 },
executor: { verbosity: -1 },
geo: { verbosity: -1 },
globalIndex: { verbosity: -1 },
index: { verbosity: -1 },
network: {
verbosity: -1,
asio: { verbosity: -1 },
bridge: { verbosity: -1 },
connectionPool: { verbosity: -1 }
},
processHealth: { verbosity: -1 },
query: {
verbosity: -1,
optimizer: { verbosity: -1 },
ce: { verbosity: -1 }
},
queryStats: { verbosity: -1 },
replication: {
verbosity: -1,
election: { verbosity: -1 },
heartbeats: { verbosity: -1 },
initialSync: { verbosity: -1 },
rollback: { verbosity: -1 }
},
sharding: {
verbosity: -1,
rangeDeleter: { verbosity: -1 },
shardingCatalogRefresh: { verbosity: -1 },
migration: { verbosity: -1 },
reshard: { verbosity: -1 },
migrationPerf: { verbosity: -1 }
},
storage: {
verbosity: -1,
recovery: { verbosity: -1 },
journal: { verbosity: -1 },
wt: {
verbosity: -1,
wtBackup: { verbosity: -1 },
wtCheckpoint: { verbosity: -1 },
wtCompact: { verbosity: -1 },
wtEviction: { verbosity: -1 },
wtHS: { verbosity: -1 },
wtRecovery: { verbosity: -1 },
wtRTS: { verbosity: -1 },
wtSalvage: { verbosity: -1 },
wtTiered: { verbosity: -1 },
wtTimestamp: { verbosity: -1 },
wtTransaction: { verbosity: -1 },
wtVerify: { verbosity: -1 },
wtWriteLog: { verbosity: -1 }
}
},
write: { verbosity: -1 },
ftdc: { verbosity: -1 },
tracking: { verbosity: -1 },
transaction: { verbosity: -1 },
tenantMigration: { verbosity: -1 },
test: { verbosity: -1 },
resourceConsumption: { verbosity: -1 },
streams: { verbosity: -1 }
},
ok: 1
}
Get Global Log Level For a Deployment获取部署的全局日志级别
The following operation gets the default logging level verbosity for a deployment:以下操作获取部署的默认日志记录级别详细程度:
db.adminCommand({getParameter: 1, logLevel: 1});
{
logLevel: 0,
ok: 1
}
Note
You can also get log verbosity levels for MongoDB components. 您还可以获取MongoDB组件的日志详细程度。For details, see 有关详细信息,请参阅db.getLogComponents().db.getLogComponents()。