Class SizeRotatingFileHandler
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.SizeRotatingFileHandler
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, FlushableCloseable, Protectable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate CountingOutputStreamprivate booleanprivate longprivate StringFields inherited from class WriterHandler
outputLockFields inherited from class ExtHandler
handlers, handlersUpdater -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance with no formatter and no output file.SizeRotatingFileHandler(long rotateSize, int maxBackupIndex) Construct a new instance with no formatter and no output file.SizeRotatingFileHandler(File file) Construct a new instance with the given output file.SizeRotatingFileHandler(File file, boolean append) Construct a new instance with the given output file and append setting.SizeRotatingFileHandler(File file, boolean append, long rotateSize, int maxBackupIndex) Construct a new instance with the given output file and append setting.SizeRotatingFileHandler(File file, long rotateSize, int maxBackupIndex) Construct a new instance with the given output file.SizeRotatingFileHandler(String fileName) Construct a new instance with the given output file.SizeRotatingFileHandler(String fileName, boolean append) Construct a new instance with the given output file and append setting. -
Method Summary
Modifier and TypeMethodDescriptionReturns the suffix set to be appended to files during rotation.booleanIndicates 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.private voidvoidSet 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.voidSets the suffix to be appended to the file name during the file rotation.Methods inherited from class FileHandler
getFile, setAppend, setFileNameMethods inherited from class OutputStreamHandler
getEncoding, setEncoding, setWriterMethods inherited from class WriterHandler
close, doPublish, flush, safeCloseMethods inherited from class ExtHandler
addHandler, checkAccess, checkAccess, clearHandlers, disableAccess, enableAccess, getHandlers, isAutoFlush, isEnabled, protect, publish, publish, removeHandler, setAutoFlush, setEnabled, setErrorManager, setFilter, setFormatter, setHandlers, setLevel, unprotectMethods inherited from class Handler
getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError
-
Field Details
-
rotateSize
private long rotateSize -
maxBackupIndex
private int maxBackupIndex -
outputStream
-
rotateOnBoot
private boolean rotateOnBoot -
suffix
-
-
Constructor Details
-
SizeRotatingFileHandler
public SizeRotatingFileHandler()Construct a new instance with no formatter and no output file. -
SizeRotatingFileHandler
Construct a new instance with the given output file.- Parameters:
file- the file- Throws:
FileNotFoundException- if the file could not be found on open
-
SizeRotatingFileHandler
Construct a new instance with the given output file and append setting.- Parameters:
file- the fileappend-trueto append,falseto overwrite- Throws:
FileNotFoundException- if the file could not be found on open
-
SizeRotatingFileHandler
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
-
SizeRotatingFileHandler
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
-
SizeRotatingFileHandler
public SizeRotatingFileHandler(long rotateSize, int maxBackupIndex) Construct a new instance with no formatter and no output file. -
SizeRotatingFileHandler
public SizeRotatingFileHandler(File file, long rotateSize, int maxBackupIndex) throws FileNotFoundException Construct a new instance with the given output file.- Parameters:
file- the file- Throws:
FileNotFoundException- if the file could not be found on open
-
SizeRotatingFileHandler
public SizeRotatingFileHandler(File file, boolean append, long rotateSize, int maxBackupIndex) throws FileNotFoundException Construct a new instance with the given output file and append setting.- Parameters:
file- the fileappend-trueto append,falseto overwrite- Throws:
FileNotFoundException- if the file could not be found on open
-
-
Method Details
-
setOutputStream
Set the output stream to write to.- Overrides:
setOutputStreamin classOutputStreamHandler- Parameters:
outputStream- the new output stream ornullfor none
-
setFile
Set the output file.- Overrides:
setFilein classFileHandler- 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
-
getSuffix
Returns the suffix set to be appended to files during rotation.- Returns:
- the suffix or
nullif no suffix should be used
-
setSuffix
Sets the suffix to be appended to the file name during the file rotation. The suffix does not play a role in determining when the file should be rotated. The suffix must be a string understood by theSimpleDateFormat. Note: Any files rotated with the suffix appended will not be deleted. ThemaxBackupIndexis not used for files with a suffix.- Parameters:
suffix- the suffix to place after the filename when the file is rotated
-
preWrite
Execute 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.- Overrides:
preWritein classWriterHandler- Parameters:
record- the record about to be logged
-
rotate
- Throws:
IOException
-