轮换 Spring 的日志 引导 运行 作为 Linux 服务
Rotating logs for Spring Boot running as Linux services
我将我的 jar 文件部署为 centos 上的一项服务,它运行良好,但我需要轮换我的日志文件,使用 logrotate 这样做没有效果,因为没有输出被发送到新的日志文件。
我正在使用 logback 并且它正在记录到文件附加程序所以我的选项是
1- 停止服务将控制台记录到日志文件并使用 logback
2- 如果可能启用 logrotate
您必须在 logrotate-config 中使用 copytruncate
选项。这对我来说就像一个魅力,但有一个小缺点,如联机帮助页中所述:
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.
我将我的 jar 文件部署为 centos 上的一项服务,它运行良好,但我需要轮换我的日志文件,使用 logrotate 这样做没有效果,因为没有输出被发送到新的日志文件。
我正在使用 logback 并且它正在记录到文件附加程序所以我的选项是
1- 停止服务将控制台记录到日志文件并使用 logback 2- 如果可能启用 logrotate
您必须在 logrotate-config 中使用 copytruncate
选项。这对我来说就像一个魅力,但有一个小缺点,如联机帮助页中所述:
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.