public class BackupStrategyWrapper extends java.lang.Object implements BackupStrategy2
BackupStrategy to fit the BackupStrategy2 interface, and perform like
a BackupStrategy with the old logic before v1.9.0.NO_LIMIT| Constructor and Description |
|---|
BackupStrategyWrapper(BackupStrategy backupStrategy) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getBackupFileName(java.lang.String fileName,
int backupIndex)
Get the backup file name for specific index.
|
int |
getMaxBackupIndex()
Get the max index of backup.
|
boolean |
shouldBackup(java.io.File file)
Whether we should backup a specified log file.
|
public BackupStrategyWrapper(BackupStrategy backupStrategy)
public int getMaxBackupIndex()
BackupStrategy2Generally, 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 returning BackupStrategy2.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_VALUE or any value less than 0, otherwise an exception will
be thrown.
getMaxBackupIndex in interface BackupStrategy2public java.lang.String getBackupFileName(java.lang.String fileName,
int backupIndex)
BackupStrategy2Generally, 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.
getBackupFileName in interface BackupStrategy2fileName - the normal file name, generated by
FileNameGenerator.generateFileName(int, long)backupIndex - the backup index, which will increase from 1 to BackupStrategy2.getMaxBackupIndex()public boolean shouldBackup(java.io.File file)
BackupStrategyshouldBackup in interface BackupStrategyfile - the log file