How to configure log4j to only keep log files for the last seven days?

前端 未结 14 1486
北海茫月
北海茫月 2020-12-02 14:01

I have the following logging problem with several Java applications using log4j for logging:

I want log files to be rotated daily, like

         


        
14条回答
  •  情歌与酒
    2020-12-02 14:39

    I came across this appender here that does what you want, it can be configured to keep a specific number of files that have been rolled over by date.

    Download: http://www.simonsite.org.uk/download.htm

    Example (groovy):

    new TimeAndSizeRollingAppender(name: 'timeAndSizeRollingAppender',
       file: 'logs/app.log', datePattern: '.yyyy-MM-dd',
       maxRollFileCount: 7, compressionAlgorithm: 'GZ',
       compressionMinQueueSize: 2,
       layout: pattern(conversionPattern: "%d [%t] %-5p %c{2} %x - %m%n"))
    

提交回复
热议问题