Class BackupStrategyWrapper
- java.lang.Object
-
- com.elvishew.xlog.internal.printer.file.backup.BackupStrategyWrapper
-
- All Implemented Interfaces:
BackupStrategy,BackupStrategy2
public class BackupStrategyWrapper extends java.lang.Object implements BackupStrategy2
Wrap aBackupStrategyto fit theBackupStrategy2interface, and perform like aBackupStrategywith the old logic before v1.9.0.
-
-
Field Summary
-
Fields inherited from interface com.elvishew.xlog.printer.file.backup.BackupStrategy2
NO_LIMIT
-
-
Constructor Summary
Constructors Constructor Description BackupStrategyWrapper(BackupStrategy backupStrategy)
-
Method Summary
All Methods Instance Methods Concrete 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.booleanshouldBackup(java.io.File file)Whether we should backup a specified log file.
-
-
-
Constructor Detail
-
BackupStrategyWrapper
public BackupStrategyWrapper(BackupStrategy backupStrategy)
-
-
Method Detail
-
getMaxBackupIndex
public int getMaxBackupIndex()
Description copied from interface:BackupStrategy2Get 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
BackupStrategy2.NO_LIMIT.
With returningBackupStrategy2.NO_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.- Specified by:
getMaxBackupIndexin interfaceBackupStrategy2- Returns:
- the max index of backup
-
getBackupFileName
public java.lang.String getBackupFileName(java.lang.String fileName, int backupIndex)Description copied from interface:BackupStrategy2Get 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.
- Specified by:
getBackupFileNamein interfaceBackupStrategy2- Parameters:
fileName- the normal file name, generated byFileNameGenerator.generateFileName(int, long)backupIndex- the backup index, which will increase from 1 toBackupStrategy2.getMaxBackupIndex()- Returns:
- the backup file name
-
shouldBackup
public boolean shouldBackup(java.io.File file)
Description copied from interface:BackupStrategyWhether we should backup a specified log file.- Specified by:
shouldBackupin interfaceBackupStrategy- Parameters:
file- the log file- Returns:
- true is we should backup the log file
-
-