Mercurial Hosting > luan
diff src/goodjava/logger/RollingFileAppender.java @ 1473:6c6ce14db6a8
add goodjava.io
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 17 Apr 2020 13:56:57 -0600 |
parents | dd14d2dce7ee |
children | 97cc73664ca8 |
line wrap: on
line diff
--- a/src/goodjava/logger/RollingFileAppender.java Fri Apr 17 11:16:38 2020 -0600 +++ b/src/goodjava/logger/RollingFileAppender.java Fri Apr 17 13:56:57 2020 -0600 @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import goodjava.io.IoUtils; public class RollingFileAppender extends WriterAppender { @@ -32,25 +33,17 @@ protected void rollOver() { close(); File backup = new File(fileName+'.'+backups); - if( backup.exists() ) { - if( !backup.delete() ) - debug("couldn't delete "+backup); - } - for( int i=backups-1; i>=1; i-- ) { - File f = backup; - backup = new File(fileName+'.'+i); - backup.renameTo(f); - } - if( !file.renameTo(backup) ) - debug("couldn't rename "+file+" to "+backup); try { + IoUtils.delete(backup); + for( int i=backups-1; i>=1; i-- ) { + File f = backup; + backup = new File(fileName+'.'+i); + IoUtils.move(backup,f); + } + IoUtils.move(file,backup); open(); } catch(IOException e) { throw new RuntimeException(e); } } - - protected void debug(String msg) { - System.err.println("RollingFileAppender: "+msg); - } }