You can specify a maximum combined storage size for MongoDB Shell log files. If the total size of all log files exceeds the maximum, log files are deleted until the combined size is below the threshold, starting with the oldest log files. By default, there is no maximum log storage size.您可以为MongoDB Shell日志文件指定最大组合存储大小。如果所有日志文件的总大小超过最大值,则从最旧的日志文件开始删除日志文件,直到组合大小低于阈值。默认情况下,没有最大日志存储大小。
About this Task关于此任务
To specify a maximum log storage size, set the 要指定最大日志存储大小,请设置logRetentionGB configuration option. logRetentionGB can be any positive float value (including less than 1).logRetentionGB配置选项。logRetentionGB可以是任何正浮点数(包括小于1的浮点数)。
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。当满足任何保留标准时,日志将被删除,从最旧的日志开始。
To check the current storage size of log files, check the size of the log folder. To see the current log folder, run the following command from the MongoDB Shell:要检查日志文件的当前存储大小,请检查日志文件夹的大小。要查看当前日志文件夹,请从MongoDB Shell运行以下命令:
config.get('logLocation')Before you Begin开始之前
To check the current maximum log storage size, run the following command:要检查当前最大日志存储大小,请运行以下命令:
config.get("logRetentionGB")Steps步骤
To modify maximum log storage size, set the 要修改最大日志存储大小,请设置logRetentionGB configuration option. logRetentionGB配置选项。You can set configuration options in the configuration API or a configuration file.您可以在配置API或配置文件中设置配置选项。
Modify Maximum Log Storage Size with the API使用API修改最大日志存储大小
The following command uses the config API to set the maximum log storage size to 3.5 GB:以下命令使用config API将最大日志存储大小设置为3.5 GB:
config.set("logRetentionGB", 3.5)
Setting "logRetentionGB" has been changedModify Maximum Log Storage Size with a Configuration File使用配置文件修改最大日志存储大小
The following configuration file sets the maximum log storage size to 3.5 GB:以下配置文件将最大日志存储大小设置为3.5 GB:
mongosh:
logRetentionGB: 3.5Disable Maximum Log Storage Size禁用最大日志存储大小
To instruct the MongoDB Shell to not delete logs based on storage size, set 要指示MongoDB Shell不根据存储大小删除日志,请将logRetentionGB to Infinity. You can perform this action through the config API or configuration file. For example:logRetentionGB设置为Infinity。您可以通过配置API或配置文件执行此操作。例如:
config.set("logRetentionGB", Infinity)
Important
To prevent log storage from growing too large, always specify at least one log retention criterion.为防止日志存储增长得太大,请始终至少指定一个日志保留标准。