Module org.jboss.logmanager
Package org.jboss.logmanager.handlers
Class PeriodicSizeRotatingFileHandler
java.lang.Object
java.util.logging.Handler
org.jboss.logmanager.ExtHandler
org.jboss.logmanager.handlers.WriterHandler
org.jboss.logmanager.handlers.OutputStreamHandler
org.jboss.logmanager.handlers.FileHandler
org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler
- All Implemented Interfaces:
Flushable,AutoCloseable
A file handler which rotates the log at a preset time interval or the size of the log.
The time interval is determined by the content of the suffix string which is passed in to
PeriodicRotatingFileHandler.setSuffix(String).
The size interval is determined by the value passed in the setRotateSize(long).- Author:
- James R. Perkins
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
PeriodicRotatingFileHandler.Period -
Field Summary
Fields inherited from class org.jboss.logmanager.ExtHandler
handlers, handlersUpdater, lock -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.PeriodicSizeRotatingFileHandler(File file, String suffix) Construct a new instance with the given output file.PeriodicSizeRotatingFileHandler(File file, String suffix, boolean append) Construct a new instance with the given output file and append setting.PeriodicSizeRotatingFileHandler(File file, String suffix, long rotateSize, int maxBackupIndex) Construct a new instance with the given output file.PeriodicSizeRotatingFileHandler(File file, String suffix, long rotateSize, int maxBackupIndex, boolean append) Construct a new instance with the given output file.PeriodicSizeRotatingFileHandler(String fileName) Construct a new instance with the given output file.PeriodicSizeRotatingFileHandler(String fileName, boolean append) Construct a new instance with the given output file and append setting. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether or a not the handler should rotate the file before the first log record is written.protected voidpreWrite(ExtLogRecord record) Execute any pre-write policy, such as file rotation.voidSet the output file.voidsetMaxBackupIndex(int maxBackupIndex) Set the maximum backup index (the number of log files to keep around).voidsetOutputStream(OutputStream outputStream) Set the output stream to write to.voidsetRotateOnBoot(boolean rotateOnBoot) Set to a value oftrueif the file should be rotated before the a new file is set.voidsetRotateSize(long rotateSize) Set the rotation size, in bytes.Methods inherited from class org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
getNextSuffix, getTimeZone, setSuffix, setTimeZoneMethods inherited from class org.jboss.logmanager.handlers.FileHandler
getFile, setAppend, setFileNameMethods inherited from class org.jboss.logmanager.handlers.OutputStreamHandler
setCharsetPrivate, setWriterMethods inherited from class org.jboss.logmanager.handlers.WriterHandler
close, doPublish, flush, isCheckHeadEncoding, isCheckTailEncoding, safeClose, setCheckHeadEncoding, setCheckTailEncodingMethods inherited from class org.jboss.logmanager.ExtHandler
addHandler, checkAccess, checkAccess, clearHandlers, getCharset, getEncoding, getErrorManager, getFilter, getFormatter, getHandlers, getLevel, isAutoFlush, isCallerCalculationRequired, isCloseChildren, isEnabled, publish, publish, publishToNestedHandlers, removeHandler, reportError, reportError, setAutoFlush, setCharset, setCloseChildren, setEnabled, setEncoding, setErrorManager, setFilter, setFormatter, setHandlers, setLevelMethods inherited from class java.util.logging.Handler
isLoggable
-
Constructor Details
-
PeriodicSizeRotatingFileHandler
public PeriodicSizeRotatingFileHandler()Default constructor. -
PeriodicSizeRotatingFileHandler
Construct a new instance with the given output file.- Parameters:
fileName- the file name- Throws:
FileNotFoundException- if the file could not be found on open
-
PeriodicSizeRotatingFileHandler
public PeriodicSizeRotatingFileHandler(String fileName, boolean append) throws FileNotFoundException Construct a new instance with the given output file and append setting.- Parameters:
fileName- the file nameappend-trueto append,falseto overwrite- Throws:
FileNotFoundException- if the file could not be found on open
-
PeriodicSizeRotatingFileHandler
Construct a new instance with the given output file.- Parameters:
file- the filesuffix- the format suffix to use- Throws:
FileNotFoundException- if the file could not be found on open
-
PeriodicSizeRotatingFileHandler
public PeriodicSizeRotatingFileHandler(File file, String suffix, boolean append) throws FileNotFoundException Construct a new instance with the given output file and append setting.- Parameters:
file- the filesuffix- the format suffix to useappend-trueto append,falseto overwrite- Throws:
FileNotFoundException- if the file could not be found on open
-
PeriodicSizeRotatingFileHandler
public PeriodicSizeRotatingFileHandler(File file, String suffix, long rotateSize, int maxBackupIndex) throws FileNotFoundException Construct a new instance with the given output file.- Parameters:
file- the filesuffix- the format suffix to userotateSize- the size the file should rotate atmaxBackupIndex- the maximum number of files to backup- Throws:
FileNotFoundException- if the file could not be found on open
-
PeriodicSizeRotatingFileHandler
public PeriodicSizeRotatingFileHandler(File file, String suffix, long rotateSize, int maxBackupIndex, boolean append) throws FileNotFoundException Construct a new instance with the given output file.- Parameters:
file- the filesuffix- the format suffix to userotateSize- the size the file should rotate atmaxBackupIndex- the maximum number of files to backupappend-trueto append,falseto overwrite- Throws:
FileNotFoundException- if the file could not be found on open
-
-
Method Details
-
setOutputStream
Description copied from class:OutputStreamHandlerSet the output stream to write to. The output stream will then belong to this handler; when the handler is closed or a new writer or output stream is set, this output stream will be closed.- Overrides:
setOutputStreamin classOutputStreamHandler- Parameters:
outputStream- the new output stream ornullfor none
-
setFile
Set the output file.- Overrides:
setFilein classPeriodicRotatingFileHandler- Parameters:
file- the file- Throws:
RuntimeException- if there is an attempt to rotate file and the rotation failsFileNotFoundException- if an error occurs opening the file
-
isRotateOnBoot
public boolean isRotateOnBoot()Indicates whether or a not the handler should rotate the file before the first log record is written.- Returns:
trueif file should rotate on boot, otherwisefalse/
-
setRotateOnBoot
public void setRotateOnBoot(boolean rotateOnBoot) Set to a value oftrueif 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 alengthgreater than 0.- Parameters:
rotateOnBoot-trueto rotate on boot, otherwisefalse
-
setRotateSize
public void setRotateSize(long rotateSize) Set the rotation size, in bytes.- Parameters:
rotateSize- the number of bytes before the log is rotated
-
setMaxBackupIndex
public void setMaxBackupIndex(int maxBackupIndex) Set the maximum backup index (the number of log files to keep around).- Parameters:
maxBackupIndex- the maximum backup index
-
preWrite
Description copied from class:PeriodicRotatingFileHandlerExecute any pre-write policy, such as file rotation. The write lock is held during this method, so make it quick. The default implementation does nothing. This implementation checks to see if the scheduled rollover time has yet occurred.- Overrides:
preWritein classPeriodicRotatingFileHandler- Parameters:
record- the record about to be logged
-