Docs Home / mongosh / Reference / Logs / Retention

Modify Maximum Log File Count修改最大日志文件计数

You can specify the maximum number of log files that the MongoDB Shell retains. After the MongoDB Shell reaches the maximum log file count, it starts deleting the oldest log files until the count is below the threshold.您可以指定MongoDB Shell保留的日志文件的最大数量。MongoDB Shell达到最大日志文件计数后,它开始删除最旧的日志文件,直到计数低于阈值。

The MongoDB Shell stores one log file for each session. By default, the MongoDB Shell stores up to 100 log files.MongoDB Shell为每个会话存储一个日志文件。默认情况下,MongoDB Shell最多存储100个日志文件。

About this Task关于此任务

You can specify multiple criteria for log retention. For example, you can specify a maximum duration for log files of 60 days and a maximum log storage size of 2GB. Logs are deleted when any retention criterion is met, starting with the oldest logs.您可以为日志保留指定多个条件。例如,您可以指定日志文件的最长持续时间为60天,最大日志存储大小为2GB。当满足任何保留标准时,日志将被删除,从最旧的日志开始。

Before you Begin开始之前

To check the current maximum log file count, run the following command:要检查当前最大日志文件计数,请运行以下命令:

config.get("logMaxFileCount")

Steps步骤

To modify the maximum log file count, set the logMaxFileCount configuration option. 要修改最大日志文件计数,请设置logMaxFileCount配置选项。You can set configuration options in the configuration API or a configuration file.您可以在配置API配置文件中设置配置选项。

Modify Maximum Log File Count with the Configuration API使用配置API修改最大日志文件计数

The following command uses the config API to set the maximum log file count to 200:以下命令使用config API将最大日志文件数设置为200:

config.set("logMaxFileCount", 200)
Setting "logMaxFileCount" has been changed

Modify Maximum Log File Count with a Configuration File使用配置文件修改最大日志文件计数

The following configuration file sets the maximum log file count to 200:以下配置文件将最大日志文件计数设置为200:

mongosh:
logMaxFileCount: 200

Disable Maximum Log File Limit禁用最大日志文件限制

To disable the maximum log file limit, set logMaxFileCount to Infinity. You can perform this action through the config API or configuration file. For example:要禁用最大日志文件限制,请将logMaxFileCount设置为Infinity。您可以通过配置API或配置文件执行此操作。例如:

config.set("logMaxFileCount", Infinity)

Important

To prevent log storage from growing too large, always specify at least one log retention criterion.为防止日志存储增长得太大,请始终至少指定一个日志保留标准。