To specify whether MongoDB Shell writes log messages, use the 要指定MongoDB Shell是否写入日志消息,请使用disableLogging configuration option. Logging is enabled by default.disableLogging配置选项。默认情况下启用日志记录。
About this Task关于此任务
When you toggle logging, the change affects the current MongoDB Shell session. You don't need to start a new session for the change to take effect.当您切换日志记录时,更改会影响当前的MongoDB Shell会话。您无需启动新会话即可使更改生效。
Before you Begin开始之前
To check if logging is currently disabled, run the following command:要检查日志记录当前是否已禁用,请运行以下命令:
config.get("disableLogging")
If the command returns如果命令返回true, logging is disabled.true,则禁用日志记录。If the command returns如果命令返回false, logging is enabled.false,则启用日志记录。
Steps步骤
You can set the 您可以使用配置API或配置文件设置disableLogging configuration option with the configuration API or a configuration file.disableLogging配置选项。
Disable Logging with the Configuration API使用配置API禁用日志记录
The following command uses the config API to disable logging for MongoDB Shell:以下命令使用config API禁用MongoDB Shell的日志记录:
config.set("disableLogging", true)
Setting "disableLogging" has been changedDisable Logging with a Configuration File使用配置文件禁用日志记录
The following configuration file disables logging for MongoDB Shell:以下配置文件禁用MongoDB Shell的日志记录:
mongosh:
disableLogging: trueRe-Enable Logging重新启用日志记录
To enable logging, set 要启用日志记录,请将disableLogging to false. You can perform this action through the config API or configuration file.disableLogging设置为false。您可以通过配置API或配置文件执行此操作。