5

log4j2 如何设置日志压缩延迟

 2 years ago
source link: https://www.v2ex.com/t/800356
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Java

log4j2 如何设置日志压缩延迟

  SimpleSS · 9 小时 25 分钟前 · 1051 次点击

请教大家一个 log4j2 的问题:

背景:在项目中目前使用 log4j2 采用 DirectWriteRolloverStrategy 方式每隔一个小时生成一个日志文件 1.log ,一个小时后生成一个新的日志文件 2.log ,同时将老的日志文件 1.log 压缩成 1.log.gz 。

问题:但是日志收集软件有概率没有读取完 1.log 或者崩溃重启,之后再读之前的那个旧的时 2.log 已经生成了,1.log 变成了压缩文件无法再读取了。有没有希望通过配置来设置压缩时间延后几个小时,生成 2.log 时不要马上将 1.log 压缩,或者保留几个未压缩过一段时间再一起压缩?

可以通过单写脚本的方式来压缩,但是 leader 更希望用 log4j2 的配置来搞这个问题,各位有好的什么办法吗。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK