Mercurial Hosting > luan
diff src/goodjava/logger/RollingFileAppender.java @ 1682:97cc73664ca8
improve RollingFileAppender
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 05 Jun 2022 10:51:43 -0600 |
parents | 6c6ce14db6a8 |
children |
line wrap: on
line diff
--- a/src/goodjava/logger/RollingFileAppender.java Fri Jun 03 09:17:21 2022 -0600 +++ b/src/goodjava/logger/RollingFileAppender.java Sun Jun 05 10:51:43 2022 -0600 @@ -7,15 +7,14 @@ public class RollingFileAppender extends WriterAppender { - protected final String fileName; + protected final String[] fileNames; protected final File file; public long maxFileSize = 10*1024*1024; - public int backups = 1; - public RollingFileAppender(Layout layout,String fileName) throws IOException { + public RollingFileAppender(Layout layout,String[] fileNames) throws IOException { super(layout,null); - this.fileName = fileName; - this.file = new File(fileName); + this.fileNames = fileNames; + this.file = new File(fileNames[0]); open(); } @@ -32,12 +31,12 @@ protected void rollOver() { close(); - File backup = new File(fileName+'.'+backups); + File backup = new File(fileNames[fileNames.length-1]); try { IoUtils.delete(backup); - for( int i=backups-1; i>=1; i-- ) { + for( int i=fileNames.length-2; i>=1; i-- ) { File f = backup; - backup = new File(fileName+'.'+i); + backup = new File(fileNames[i]); IoUtils.move(backup,f); } IoUtils.move(file,backup);