Docs 菜单
Docs 主页
/
MongoDB Manual
/ / /

db.setLogLevel()

在此页面上

  • 定义
  • 兼容性
  • 行为
  • 示例
db.setLogLevel()

日志消息设置单一详细程度。

db.setLogLevel() 采用以下形式:

db.setLogLevel(<level>, <component>)

db.setLogLevel() 使用以下参数:

Parameter
类型
说明
level
int

日志详细程度。

详细程度级别的范围可以从 05

  • 0 是 MongoDB 的默认日志详细程度级别,它包括信息性消息。

  • 15 提高详细程度级别以包括调试消息。

要继承组件父级的详细程度,也可以指定 -1

component
字符串

可选。为其指定日志详细程度的组件的名称。组件名称对应于相应 systemLog.component.<name>.verbosity 设置中的 <name>

省略以指定所有组件的默认详细程度。

此方法可用于以下环境中托管的部署:

重要

db.setLogLevel() 设置单个详细程度。如要在一次操作中设置多个详细程度,可使用 setParameter 命令设置 logComponentVerbosity 参数。您还可以在配置文件中指定详细程度设置。有关示例,请参阅配置日志详细程度。

注意

从版本 4.2 开始,MongoDB 在日志消息中包含调试详细级别(1 至 5 级)。例如,如果详细级别为 2,则 MongoDB 记录 D2。在以前版本中,MongoDB 日志消息仅为调试级别指定 D

省略 <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
}

指定 <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
}

以下操作获取部署的默认日志记录级别详细程度:

db.adminCommand({getParameter: 1, logLevel: 1});
{
logLevel: 0,
ok: 1
}

注意

您还可以获取 MongoDB 组件的日志详细级别。有关详细信息,请参阅db.getLogComponents()

后退

db.serverStatus