Interface BackupStrategy2
-
- All Superinterfaces:
BackupStrategy
- All Known Implementing Classes:
AbstractBackupStrategy,BackupStrategyWrapper,FileSizeBackupStrategy2
public interface BackupStrategy2 extends BackupStrategy
Decide whether and how the log file should be backed up and use a new file for next logging.- Since:
- 1.9.0
-
-
Field Summary
Fields Modifier and Type Field Description static intNO_LIMITDon't limit the backup index, which means there is no limit to the number of backup files.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.StringgetBackupFileName(java.lang.String fileName, int backupIndex)Get the backup file name for specific index.intgetMaxBackupIndex()Get the max index of backup.-
Methods inherited from interface com.elvishew.xlog.printer.file.backup.BackupStrategy
shouldBackup
-
-
-
-
Field Detail
-
NO_LIMIT
static final int NO_LIMIT
Don't limit the backup index, which means there is no limit to the number of backup files.- See Also:
- Constant Field Values
-
-
Method Detail
-
getMaxBackupIndex
int getMaxBackupIndex()
Get the max index of backup.Generally, the max index should be greater than 1, and recommended to be less than 10.
Imagine the normal log file name is 'log', and max backup index is 'n', as the log grows, a log record would go from 'log' to 'log.bak.1', then to 'log.bak.2', 'log.bak.3', and finally to 'log.bak.n', the greater index, the older log.
After that, the log record will no longer exist in the file system.If you don't want to limit the max index, then return
NO_LIMIT.
With returningNO_LIMIT, When you backing up, the oldest log would be saved to 'log.bak.1', and then 'log.bak.2'...'log.bak.n', the greater index, the newer log.Don't return
Integer.MAX_VALUEor any value less than 0, otherwise an exception will be thrown.- Returns:
- the max index of backup
-
getBackupFileName
java.lang.String getBackupFileName(java.lang.String fileName, int backupIndex)Get the backup file name for specific index.Generally, a backup file with normal file name 'log' and index 'n' could simply be 'log.bak.n', you can specify your own naming rules, by overriding this method.
Make sure to return different backup file name with different backup index, and same backup file name with same index. Otherwise, it will lead to unexpected behavior.
- Parameters:
fileName- the normal file name, generated byFileNameGenerator.generateFileName(int, long)backupIndex- the backup index, which will increase from 1 togetMaxBackupIndex()- Returns:
- the backup file name
-
-