public void rollOver ( ) { Resource target ; Resource file ; if ( qw != null ) { long size = ( ( CountingQuietWriter ) qw ) . getCount ( ) ; LogLog . debug ( "rolling over count=" + size ) ; // if operation fails, do not roll again until // maxFileSize more bytes are written nextRollover = size + maxFileSize ; } LogLog . debug ( "maxBackupIndex=" + maxBackupIndex ) ; boolean renameSucceeded = true ; Resource parent = res . getParentResource ( ) ; // If maxBackups <= 0, then there is no file renaming to be done. if ( maxBackupIndex > 0 ) { // Delete the oldest file, to keep Windows happy. file = parent . getRealResource ( res . getName ( ) + "." + maxBackupIndex + ".bak" ) ; if ( file . exists ( ) ) renameSucceeded = file . delete ( ) ; // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} for ( int i = maxBackupIndex - 1 ; i >= 1 && renameSucceeded ; i -- ) { file = parent . getRealResource ( res . getName ( ) + "." + i + ".bak" ) ; if ( file . exists ( ) ) { target = parent . getRealResource ( res . getName ( ) + "." + ( i + 1 ) + ".bak" ) ; LogLog . debug ( "Renaming file " + file + " to " + target ) ; renameSucceeded = file . renameTo ( target ) ; } } if ( renameSucceeded ) { // Rename fileName to fileName.1 target = parent . getRealResource ( res . getName ( ) + ".1.bak" ) ; this . closeFile ( ) ; // keep windows happy. file = res ; LogLog . debug ( "Renaming file " + file + " to " + target ) ; renameSucceeded = file . renameTo ( target ) ; // if file rename failed, reopen file with append = true if ( ! renameSucceeded ) { try { this . setFile ( true ) ; } catch ( IOException e ) { LogLog . error ( "setFile(" + res + ", true) call failed." , e ) ; } } } } // if all renames were successful, then if ( renameSucceeded ) { try { // This will also close the file. This is OK since multiple // close operations are safe. this . setFile ( false ) ; nextRollover = 0 ; } catch ( IOException e ) { LogLog . error ( "setFile(" + res + ", false) call failed." , e ) ; } } }
Implements the usual roll over behavior .