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 valueRollover scheduleExample
/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

原文地址:https://www.cnblogs.com/leegoo/p/15572872.html