Class FileSizeBackupStrategy2

    • Constructor Detail

      • FileSizeBackupStrategy2

        public FileSizeBackupStrategy2​(long maxSize,
                                       int maxBackupIndex)
        Constructor.
        Parameters:
        maxSize - the max size the file can reach
        maxBackupIndex - the max backup index, or BackupStrategy2.NO_LIMIT, see getMaxBackupIndex()
    • Method Detail

      • shouldBackup

        public boolean shouldBackup​(java.io.File file)
        Description copied from interface: BackupStrategy
        Whether 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: BackupStrategy2
        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 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.

        Returns:
        the max index of backup