java - Spring Boot 服务中的日志轮换

标签 java linux logrotate

我正在将 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/

相关文章:

linux - 压缩删除logrotate中的日志

Java查找不那么具体的字符串

java - 通过链接更新桌面背景

php - 使用 PHP 在 Linux 服务器上运行 C++ 可执行文件

linux - 如何让vimrc修改生效

c - string3.h中__warn_memset_zero_len的定义在哪里

java - 升级到 Oracle JDBC 瘦驱动程序会导致 SQLException : Unexpected exception while enlisting XAConnection

java - 如何避免 BuildPath 中的循环(特定项目设置)

docker - Docker日志填充正在运行的容器

ruby-on-rails - 为 Rails 应用设置 logrotate