我正在将 Spring Boot 2.0.0-RC1 应用程序部署为 init.d service ,但我不知道如何配置日志轮换。 该应用程序记录到/var/log/appname.log,但如果我配置 logrotate,记录将在轮换后停止,因为创建了一个新文件,并且嵌入式脚本中定义的 stdout/stderr 重定向不再起作用。
如果我在我的日志系统中配置日志轮转,会有两个问题:我无法在/var/log 中创建文件,并且我仍然在嵌入式脚本中定义了重定向。
什么是正确的解决方案?
最佳答案
我在多个应用程序中面临同样的问题,添加 copytruncate
参数是解决方案,因为您的 Spring Boot 应用程序不了解文件已更改(截断)并且表现得像 tail -f
命令(详见 How does the “tail” command's “-f” parameter work?)。
示例:
/opt/payara41/glassfish/domains/domain1/logs/* {
daily
copytruncate
rotate 3
dateext
notifempty
}
copytruncate
Truncate the original log file to zero size 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
关于java - Spring Boot 服务中的日志轮换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48681916/