db.setLogLevel()
定义
db.setLogLevel()
db.setLogLevel()
采用以下形式:db.setLogLevel(<level>, <component>) db.setLogLevel()
使用以下参数:Parameter类型说明level
intcomponent
字符串可选。为其指定日志详细程度的组件的名称。组件名称对应于相应
systemLog.component.<name>.verbosity
设置中的<name>
:省略以指定所有组件的默认详细程度。
兼容性
此方法可用于以下环境中托管的部署:
重要
MongoDB Atlas集群不支持此命令。 有关Atlas支持所有命令的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
行为
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()
。