1

is there any way i can zip the previous logs directory if exists and start fresh(creating new dir everytime system starts) in slf4j with logback.xml ?

PS: I am using java7.

Thanks

Mike
  • 615
  • 1
  • 6
  • 10

1 Answers1

0

With the help of logback. Rolling policy is for that purpose. Set the retantion days and the pass for storing the zip log. MaxHistory amount of days after the file will be archived.

   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/yourLog.log</file>
      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <FileNamePattern>../../logs/backup/yourLog_%d{yyyy-MM-dd}.log.gz</FileNamePattern>
        <MaxHistory>32</MaxHistory>
      </rollingPolicy>
   </appender>
Echoinacup
  • 482
  • 4
  • 12
  • thanks for your comments. However i am looking to zip the whole directory and start fresh. – Mike Jan 10 '19 at 11:15
  • @Mike you are welcome ;) you could check https://stackoverflow.com/questions/25844215/create-new-log-file-each-run-in-logback but I can not find zipping folder :) Could you let me know if you find it? Thank you – Echoinacup Jan 10 '19 at 11:23