Docs Home / mongosh / Reference / Logs

Disable Logging禁用日志记录

To specify whether MongoDB Shell writes log messages, use the disableLogging configuration option. Logging is enabled by default.要指定MongoDB Shell是否写入日志消息,请使用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 disableLogging configuration option with the configuration API or a configuration file.您可以使用配置API配置文件设置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 changed

Disable Logging with a Configuration File使用配置文件禁用日志记录

The following configuration file disables logging for MongoDB Shell:以下配置文件禁用MongoDB Shell的日志记录:

mongosh:
disableLogging: true

Re-Enable Logging重新启用日志记录

To enable logging, set disableLogging to false. You can perform this action through the config API or configuration file.要启用日志记录,请将disableLogging设置为false。您可以通过配置API或配置文件执行此操作。