/** {@inheritDoc} This implementation checks to see if the scheduled rollover time has yet occurred. */ protected void preWrite(final ExtLogRecord record) { final long recordMillis = record.getMillis(); if (recordMillis >= nextRollover) { rollOver(); calcNextRollover(recordMillis); } }
private void rollOver() { try { final File file = getFile(); // first, close the original file (some OSes won't let you move/rename a file that is open) setFile(null); // next, rotate it suffixRotator.rotate(getErrorManager(), file.toPath(), nextSuffix); // start new file setFile(file); } catch (IOException e) { reportError("Unable to rotate log file", e, ErrorManager.OPEN_FAILURE); } }
/** * Construct a new instance with the given output file. * * @param file the file * @param suffix the format suffix to use * * @throws java.io.FileNotFoundException if the file could not be found on open */ public PeriodicRotatingFileHandler(final File file, final String suffix) throws FileNotFoundException { super(file); setSuffix(suffix); }
for (int i = 0; i < len; i ++) { switch (dateSuffix.charAt(i)) { case 'y': period = min(period, Period.YEAR); break; case 'M': period = min(period, Period.MONTH); break; case 'w': case 'W': period = min(period, Period.WEEK); break; case 'D': case 'd': case 'F': case 'E': period = min(period, Period.DAY); break; case 'a': period = min(period, Period.HALF_DAY); break; case 'H': case 'k': case 'K': case 'h': period = min(period, Period.HOUR); break; case 'm': period = min(period, Period.MINUTE); break; case '\'': while (dateSuffix.charAt(++i) != '\''); break; case 's': this.suffixRotator = suffixRotator; final long now; final File file = getFile(); if (file != null && file.lastModified() > 0) { now = file.lastModified(); now = System.currentTimeMillis(); calcNextRollover(now);
@Override public void setFile(final File file) throws FileNotFoundException { synchronized (outputLock) { super.setFile(file); if (format != null && file != null && file.lastModified() > 0) { calcNextRollover(file.lastModified()); } } }
@Override public void setOutputStream(final OutputStream outputStream) { synchronized (outputLock) { this.outputStream = outputStream == null ? null : new CountingOutputStream(outputStream); super.setOutputStream(this.outputStream); } }
/** * {@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(); } }
@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); } } } }
/** * Construct a new instance with the given output file and append setting. * * @param file the file * @param suffix the format suffix to use * @param append {@code true} to append, {@code false} to overwrite * @throws java.io.FileNotFoundException if the file could not be found on open */ public PeriodicRotatingFileHandler(final File file, final String suffix, final boolean append) throws FileNotFoundException { super(file, append); setSuffix(suffix); }