对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db.setLogLevel()(mongosh方法)

db.setLogLevel()

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

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

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

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

Parameter
类型
说明

level

int

日志详细程度。

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

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

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

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

component

字符串

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

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

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

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.

注意

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

省略 <component> 参数可为所有组件设置默认详细程度;即 systemLog.verbosity 设置。该操作将默认详细程度设置为 1

db.setLogLevel(1)

指定 <component> 参数可为组件设置详细程度。以下操作可将 systemLog.component.storage.journal.verbosity 更新为 2

db.setLogLevel(2, "storage.journal" )

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

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

注意

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

给本页内容打分