Class FileSizeBackupStrategy2
- java.lang.Object
-
- com.elvishew.xlog.printer.file.backup.AbstractBackupStrategy
-
- com.elvishew.xlog.printer.file.backup.FileSizeBackupStrategy2
-
- All Implemented Interfaces:
BackupStrategy,BackupStrategy2
public class FileSizeBackupStrategy2 extends AbstractBackupStrategy
Limit the file size of a max length.- Since:
- 1.9.0
-
-
Field Summary
-
Fields inherited from interface com.elvishew.xlog.printer.file.backup.BackupStrategy2
NO_LIMIT
-
-
Constructor Summary
Constructors Constructor Description FileSizeBackupStrategy2(long maxSize, int maxBackupIndex)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxBackupIndex()Get the max index of backup.booleanshouldBackup(java.io.File file)Whether we should backup a specified log file.-
Methods inherited from class com.elvishew.xlog.printer.file.backup.AbstractBackupStrategy
getBackupFileName
-
-
-
-
Constructor Detail
-
FileSizeBackupStrategy2
public FileSizeBackupStrategy2(long maxSize, int maxBackupIndex)Constructor.- Parameters:
maxSize- the max size the file can reachmaxBackupIndex- the max backup index, orBackupStrategy2.NO_LIMIT, seegetMaxBackupIndex()
-
-
Method Detail
-
shouldBackup
public boolean shouldBackup(java.io.File file)
Description copied from interface:BackupStrategyWhether we should backup a specified log file.- Parameters:
file- the log file- Returns:
- true is we should backup the log file
-
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.- Returns:
- the max index of backup
-
-