/** * Set the rotation size, in bytes. * * @param rotateSize the number of bytes before the log is rotated */ public void setRotateSize(final long rotateSize) { checkAccess(this); synchronized (outputLock) { this.rotateSize = rotateSize; } }
@Override protected void preWrite(final ExtLogRecord record) { super.preWrite(record); final int maxBackupIndex = this.maxBackupIndex; final long currentSize = (outputStream == null ? Long.MIN_VALUE : outputStream.currentSize); if (currentSize > rotateSize && maxBackupIndex > 0) { try { final File file = getFile(); if (file == null) { // no file is set; a direct output stream or writer was specified return; } // close the old file. setFile(null); getSuffixRotator().rotate(getErrorManager(), file.toPath(), getNextSuffix(), maxBackupIndex); // start with new file. setFile(file); } catch (IOException e) { reportError("Unable to rotate log file", e, ErrorManager.OPEN_FAILURE); } } } }
/** * {@inheritDoc} * * @throws RuntimeException if there is an attempt to rotate file and the rotation fails */ @Override public void setFile(final File file) throws FileNotFoundException { synchronized (outputLock) { // Check for a rotate if (rotateOnBoot && maxBackupIndex > 0 && file != null && file.exists() && file.length() > 0L) { final String suffix = getNextSuffix(); final SuffixRotator suffixRotator = getSuffixRotator(); if (suffixRotator != SuffixRotator.EMPTY && suffix != null) { suffixRotator.rotate(getErrorManager(), file.toPath(), suffix, maxBackupIndex); } } super.setFile(file); if (outputStream != null) outputStream.currentSize = file == null ? 0L : file.length(); } }
/** * Set to a value of {@code true} if the file should be rotated before the a new file is set. The rotation only * happens if the file names are the same and the file has a {@link java.io.File#length() length} greater than 0. * * @param rotateOnBoot {@code true} to rotate on boot, otherwise {@code false} */ public void setRotateOnBoot(final boolean rotateOnBoot) { checkAccess(this); synchronized (outputLock) { this.rotateOnBoot = rotateOnBoot; } }
/** * Set the maximum backup index (the number of log files to keep around). * * @param maxBackupIndex the maximum backup index */ public void setMaxBackupIndex(final int maxBackupIndex) { checkAccess(this); synchronized (outputLock) { this.maxBackupIndex = maxBackupIndex; } }