Docs Home / mongosh / Reference / Logs

Enable Log Compression启用日志压缩

You can enable compression for MongoDB Shell log files. By default, MongoDB Shell does not compress log files.您可以为MongoDB Shell日志文件启用压缩。默认情况下,MongoDB Shell不压缩日志文件。

About this Task关于此任务

When log compression is enabled, MongoDB Shell compresses log files with gzip.启用日志压缩时,MongoDB Shell使用gzip压缩日志文件。

After you toggle log compression, you must start a new MongoDB Shell session for the change to take effect.切换日志压缩后,必须启动新的MongoDB Shell会话才能使更改生效。

Before you Begin开始之前

To check if log compression is enabled, run the following command from MongoDB Shell:要检查是否启用了日志压缩,请从MongoDB Shell运行以下命令:

config.get("logCompressionEnabled")

Steps步骤

To enable log compression, set the logCompressionEnabled configuration option to true. 要启用日志压缩,请将logCompressionEnabled配置选项设置为trueYou can set configuration options in the configuration API or a configuration file.您可以在配置API配置文件中设置配置选项。

Enable Log Compression with the Configuration API使用配置API启用日志压缩

The following command uses the config API to enable log compression:以下命令使用config API启用日志压缩:

config.set("logCompressionEnabled", true)
Setting "logCompressionEnabled" has been changed

Enable Log Compression with a Configuration File使用配置文件启用日志压缩

The following configuration file enables log compression:以下配置文件支持日志压缩:

mongosh:
logCompressionEnabled: true

Disable Log Compression禁用日志压缩

To disable log compression, set logCompressionEnabled to false. You can perform this action through the config API or configuration file.要禁用日志压缩,请将logCompressionEnabled设置为false。您可以通过配置API或配置文件执行此操作。