logback 归档日志自动压缩


需要添加依赖 apache-log4j-extras-X.X.X.jar

fileNamePattern 以gz或者zip结尾即可

 

 补充说明:

新生成归档gz日志文件,服务器上 vim查看和文本文件没有区别

可以用gzip -l 查看压缩率,确实为压缩文件,grep查不到内容,需要用zgrep

ftp到window机器上用解压缩软件可以看到是压缩文件

 

参考资料:http://logging.apache.org/log4j/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html

Automatic file compression

TimeBasedRollingPolicy supports automatic file compression. This feature is enabled if the value of the FileNamePattern option ends with .gz or .zip.

 

 

FileNamePattern value Rollover schedule Example
/wombat/foo.%d.gz Daily rollover (at midnight) with automatic GZIP compression of the archived files. During November 23rd, 2004, logging output will go to the file /wombat/foo.2004-11-23. However, at midnight that file will be compressed to become /wombat/foo.2004-11-23.gz. For the 24th of November, logging output will be directed to /wombat/folder/foo.2004-11-24 until its rolled over at the beginning of the next day.

参考资料:https://blog.csdn.net/rootcn/article/details/30237401


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM