org.apache.log4j.helpers.CountingQuietWriter Java Examples

The following examples show how to use org.apache.log4j.helpers.CountingQuietWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeRollingAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Handles append time behavior for CompositeRollingAppender.  This checks
 * if a roll over either by date (checked first) or time (checked second)
 * is need and then appends to the file last.
*/
protected void subAppend(LoggingEvent event) {

	if (rollDate) {
		long n = System.currentTimeMillis();
		if (n >= nextCheck) {
			now.setTime(n);
			nextCheck = rc.getNextCheckMillis(now);

			rollOverTime();
		}
	}

	if (rollSize) {
		if ((fileName != null) && ((CountingQuietWriter) qw).getCount() >= maxFileSize) {
		    rollOverSize();
		}
	}

	super.subAppend(event);
}
 
Example #2
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
/**
 * Implements the usual roll over behaviour.
 * <p>
 * <code>File</code> is renamed <code>File.yyyyMMddHHmmss</code> and closed. A
 * new <code>File</code> is created to receive further log output.
 */
// synchronization not necessary since doAppend is alreasy synched
public void rollOver() {
  if (qw != null) {
    long size = ((CountingQuietWriter) qw).getCount();
    LogLog.debug("rolling over count=" + size);
    // if operation fails, do not roll again until
    // maxFileSize more bytes are written
    nextRollover = size + maxFileSize;
  }

  this.closeFile(); // keep windows happy.

  String newFileName = getLogFileName(fileName);
  try {
    // This will also close the file. This is OK since multiple
    // close operations are safe.
    this.setFile(newFileName, false, bufferedIO, bufferSize);
    nextRollover = 0;
  } catch (IOException e) {
    if (e instanceof InterruptedIOException) {
      Thread.currentThread().interrupt();
    }
    LogLog.error("setFile(" + newFileName + ", false) call failed.", e);
  }
}
 
Example #3
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
/**
 * Implements the usual roll over behaviour.
 * <p>
 * <code>File</code> is renamed <code>File.yyyyMMddHHmmss</code> and closed. A
 * new <code>File</code> is created to receive further log output.
 */
// synchronization not necessary since doAppend is alreasy synched
public void rollOver() {
  if (qw != null) {
    long size = ((CountingQuietWriter) qw).getCount();
    LogLog.debug("rolling over count=" + size);
    // if operation fails, do not roll again until
    // maxFileSize more bytes are written
    nextRollover = size + maxFileSize;
  }

  this.closeFile(); // keep windows happy.

  String newFileName = getLogFileName(fileName);
  try {
    // This will also close the file. This is OK since multiple
    // close operations are safe.
    this.setFile(newFileName, false, bufferedIO, bufferSize);
    nextRollover = 0;
  } catch (IOException e) {
    if (e instanceof InterruptedIOException) {
      Thread.currentThread().interrupt();
    }
    LogLog.error("setFile(" + newFileName + ", false) call failed.", e);
  }
}
 
Example #4
Source File: SizeRollingFileAppender.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
/**
This method differentiates RollingFileAppender from its super
class.

@since 0.9.0
*/
@Override
protected void subAppend(
                          LoggingEvent event ) {

    super.subAppend(event);
    if (fileName != null && qw != null) {
        long size = ((CountingQuietWriter) qw).getCount();
        if (size >= maxFileSize && size >= nextRollover) {
            rollOver();
        }
    }
}
 
Example #5
Source File: RollingFileAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public
synchronized
void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize)
                                                               throws IOException {
  super.setFile(fileName, append, this.bufferedIO, this.bufferSize);
  if(append) {
    File f = new File(fileName);
    ((CountingQuietWriter) qw).setCount(f.length());
  }
}
 
Example #6
Source File: RollingFileAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
   This method differentiates RollingFileAppender from its super
   class.

   @since 0.9.0
*/
protected
void subAppend(LoggingEvent event) {
  super.subAppend(event);
  if(fileName != null && qw != null) {
      long size = ((CountingQuietWriter) qw).getCount();
      if (size >= maxFileSize && size >= nextRollover) {
          rollOver();
      }
  }
 }
 
Example #7
Source File: CompositeRollingAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates and opens the file for logging.  If <code>staticLogFileName</code>
 * is false then the fully qualified name is determined and used.
 */
public synchronized void setFile(String fileName, boolean append) throws IOException {
	if (!staticLogFileName) {
	    scheduledFilename = fileName = fileName.trim() + sdf.format(now);
		if (countDirection > 0) {
			scheduledFilename = fileName = fileName + '.' + (++curSizeRollBackups);
		}
	}

	super.setFile(fileName, append);
	if(append) {
	  File f = new File(fileName);
	  ((CountingQuietWriter) qw).setCount(f.length());
	}
}
 
Example #8
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
public synchronized void setFile(String fileName, boolean append,
    boolean bufferedIO, int bufferSize) throws IOException {
  super.setFile(fileName, append, this.bufferedIO, this.bufferSize);
  if (append) {
    File f = new File(fileName);
    ((CountingQuietWriter) qw).setCount(f.length());
  }
}
 
Example #9
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
/**
 * This method differentiates RollingFileAppender from its super class.
 */
protected void subAppend(LoggingEvent event) {
  super.subAppend(event);

  if (fileName != null && qw != null) {
    long size = ((CountingQuietWriter) qw).getCount();
    if (size >= maxFileSize && size >= nextRollover) {
      rollOver();
    }
  }
}
 
Example #10
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
public synchronized void setFile(String fileName, boolean append,
    boolean bufferedIO, int bufferSize) throws IOException {
  super.setFile(fileName, append, this.bufferedIO, this.bufferSize);
  if (append) {
    File f = new File(fileName);
    ((CountingQuietWriter) qw).setCount(f.length());
  }
}
 
Example #11
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
/**
 * This method differentiates RollingFileAppender from its super class.
 */
protected void subAppend(LoggingEvent event) {
  super.subAppend(event);

  if (fileName != null && qw != null) {
    long size = ((CountingQuietWriter) qw).getCount();
    if (size >= maxFileSize && size >= nextRollover) {
      rollOver();
    }
  }
}
 
Example #12
Source File: RollingFileAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected
void setQWForFiles(Writer writer) {
   this.qw = new CountingQuietWriter(writer, errorHandler);
}
 
Example #13
Source File: CompositeRollingAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void setQWForFiles(Writer writer) {
    qw = new CountingQuietWriter(writer, errorHandler);
}
 
Example #14
Source File: CompositeRollingAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 Implements roll overs base on file size.

 <p>If the maximum number of size based backups is reached
 (<code>curSizeRollBackups == maxSizeRollBackups</code) then the oldest
 file is deleted -- it's index determined by the sign of countDirection.<br>
 If <code>countDirection</code> < 0, then files
 {<code>File.1</code>, ..., <code>File.curSizeRollBackups -1</code>}
 are renamed to {<code>File.2</code>, ...,
 <code>File.curSizeRollBackups</code>}.	 Moreover, <code>File</code> is
 renamed <code>File.1</code> and closed.<br>

 A new file is created to receive further log output.

 <p>If <code>maxSizeRollBackups</code> is equal to zero, then the
 <code>File</code> is truncated with no backup files created.

 <p>If <code>maxSizeRollBackups</code> < 0, then <code>File</code> is
 renamed if needed and no files are deleted.
*/

// synchronization not necessary since doAppend is alreasy synched
protected void rollOverSize() {
	File file;

	this.closeFile(); // keep windows happy.

	LogLog.debug("rolling over count=" + ((CountingQuietWriter) qw).getCount());
	LogLog.debug("maxSizeRollBackups = " + maxSizeRollBackups);
	LogLog.debug("curSizeRollBackups = " + curSizeRollBackups);
	LogLog.debug("countDirection = " + countDirection);

	// If maxBackups <= 0, then there is no file renaming to be done.
	if (maxSizeRollBackups != 0) {

		if (countDirection < 0) {
			// Delete the oldest file, to keep Windows happy.
			if (curSizeRollBackups == maxSizeRollBackups) {
			    deleteFile(fileName + '.' + maxSizeRollBackups);
				curSizeRollBackups--;
			}

			// Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
			for (int i = curSizeRollBackups; i >= 1; i--) {
				rollFile((fileName + "." + i), (fileName + '.' + (i + 1)));
			}

			curSizeRollBackups++;
			// Rename fileName to fileName.1
			rollFile(fileName, fileName + ".1");

		} //REMOVE This code branching for Alexander Cerna's request
		else if (countDirection == 0) {
			//rollFile based on date pattern
			curSizeRollBackups++;
			now.setTime(System.currentTimeMillis());
			scheduledFilename = fileName + sdf.format(now);
			rollFile(fileName, scheduledFilename);
		}
		else { //countDirection > 0
			if (curSizeRollBackups >= maxSizeRollBackups && maxSizeRollBackups > 0) {
				//delete the first and keep counting up.
				int oldestFileIndex = curSizeRollBackups - maxSizeRollBackups + 1;
				deleteFile(fileName + '.' + oldestFileIndex);
			}

			if (staticLogFileName) {
				curSizeRollBackups++;
				rollFile(fileName, fileName + '.' + curSizeRollBackups);
			}
		}
	}

	try {
		// This will also close the file. This is OK since multiple
		// close operations are safe.
		this.setFile(baseFileName, false);
	}
	catch(IOException e) {
		LogLog.error("setFile("+fileName+", false) call failed.", e);
	}
}
 
Example #15
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
protected void setQWForFiles(Writer writer) {
  this.qw = new CountingQuietWriter(writer, errorHandler);
}
 
Example #16
Source File: RollingFileWithoutDeleteAppender.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
protected void setQWForFiles(Writer writer) {
  this.qw = new CountingQuietWriter(writer, errorHandler);
}