gpt4 book ai didi

logging - Spring Boot linux 服务不轮换日志文件

转载 作者:行者123 更新时间:2023-12-02 10:10:55 25 4
gpt4 key购买 nike

根据spring boot 1.4 docs当文件大小达到 10MB 时,Spring Boot 会自动轮换日志文件。我在 Linux 机器上部署了 spring boot v1.4.2 服务,但文件不旋转。文件已达到 118 MB,但仍然不会自动旋转。

我是否遗漏了文档中的某些内容或错误?

最佳答案

Linux 计算机上日志轮转的另一个选项是使用 logrotate使用copytruncate参数。

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

logrotate reads everything about the log files it should be handling from the series of configuration files specified on the command line. Each configuration file can set global options (local definitions override global ones, and later definitions override earlier ones) and specify logfiles to rotate. A simple configuration file looks like this:

copytruncate

Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

将此条目添加到 logrotate 配置文件

/var/log/spring.log {
daily
copytruncate
rotate 3
dateext
notifempty
}

下一步是什么?请参阅How to make log-rotate change take effect?

logrotate uses crontab to work. It's scheduled work, not a daemon, so no need to reload its configuration.

关于logging - Spring Boot linux 服务不轮换日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41996064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com