Package org.jboss.logmanager.handlers

## 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:
  `java.io.Closeable`, `java.io.Flushable`, `java.lang.AutoCloseable`, `FlushableCloseable`, `Protectable`

    public class SizeRotatingFileHandler
    extends FileHandler

### Field Summary

### Fields inherited from class org.jboss.logmanager.ExtHandler

`handlers, handlersUpdater`

### Fields inherited from class org.jboss.logmanager.handlers.WriterHandler

`outputLock`

### Constructor Summary

Constructors
`SizeRotatingFileHandler()` Construct 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​(java.io.File file)` Construct a new instance with the given output file.
`SizeRotatingFileHandler​(java.io.File file, boolean append)` Construct a new instance with the given output file and append setting.
`SizeRotatingFileHandler​(java.io.File file, boolean append, long rotateSize, int maxBackupIndex)` Construct a new instance with the given output file and append setting.
`SizeRotatingFileHandler​(java.io.File file, long rotateSize, int maxBackupIndex)` Construct a new instance with the given output file.
`SizeRotatingFileHandler​(java.lang.String fileName)` Construct a new instance with the given output file.
`SizeRotatingFileHandler​(java.lang.String fileName, boolean append)` Construct a new instance with the given output file and append setting.

### Method Summary

All Methods Instance Methods Concrete Methods
`java.lang.String` `getSuffix()` Returns the suffix set to be appended to files during rotation.
`boolean` `isRotateOnBoot()` Indicates whether or a not the handler should rotate the file before the first log record is written.
`protected void` `preWrite​(ExtLogRecord record)` Execute any pre-write policy, such as file rotation.
`void` `setFile​(java.io.File file)` Set the output file.
`void` `setMaxBackupIndex​(int maxBackupIndex)` Set the maximum backup index (the number of log files to keep around).
`void` `setOutputStream​(java.io.OutputStream outputStream)` Set the output stream to write to.
`void` `setRotateOnBoot​(boolean rotateOnBoot)` Set to a value of `true` if the file should be rotated before the a new file is set.
`void` `setRotateSize​(long rotateSize)` Set the rotation size, in bytes.
`void` `setSuffix​(java.lang.String suffix)` Sets the suffix to be appended to the file name during the file rotation.

### Methods inherited from class org.jboss.logmanager.ExtHandler

`addHandler, checkAccess, checkAccess, clearHandlers, disableAccess, enableAccess, getHandlers, isAutoFlush, isCallerCalculationRequired, isCloseChildren, isEnabled, protect, publish, publish, removeHandler, setAutoFlush, setCloseChildren, setEnabled, setErrorManager, setFilter, setFormatter, setHandlers, setLevel, unprotect`

### Methods inherited from class org.jboss.logmanager.handlers.FileHandler

`getFile, setAppend, setFileName`

### Methods inherited from class java.util.logging.Handler

`getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from class org.jboss.logmanager.handlers.OutputStreamHandler

`getEncoding, setEncoding, setWriter`

### Methods inherited from class org.jboss.logmanager.handlers.WriterHandler

`close, doPublish, flush, safeClose`

### Constructor Detail

#### SizeRotatingFileHandler

    public SizeRotatingFileHandler()

Construct a new instance with no formatter and no output file.

#### SizeRotatingFileHandler

    public SizeRotatingFileHandler​(java.io.File file)
                            throws java.io.FileNotFoundException

Construct a new instance with the given output file.

Parameters:
  `file` - the file
Throws:
  `java.io.FileNotFoundException` - if the file could not be found on open

#### SizeRotatingFileHandler

    public SizeRotatingFileHandler​(java.io.File file,
                                   boolean append)
                            throws java.io.FileNotFoundException

Construct a new instance with the given output file and append setting.

Parameters:
  `file` - the file
  `append` - `true` to append, `false` to overwrite
Throws:
  `java.io.FileNotFoundException` - if the file could not be found on open

#### SizeRotatingFileHandler

    public SizeRotatingFileHandler​(java.lang.String fileName)
                            throws java.io.FileNotFoundException

Construct a new instance with the given output file.

Parameters:
  `fileName` - the file name
Throws:
  `java.io.FileNotFoundException` - if the file could not be found on open

#### SizeRotatingFileHandler

    public SizeRotatingFileHandler​(java.lang.String fileName,
                                   boolean append)
                            throws java.io.FileNotFoundException

Construct a new instance with the given output file and append setting.

Parameters:
  `fileName` - the file name
  `append` - `true` to append, `false` to overwrite
Throws:
  `java.io.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​(java.io.File file,
                                   long rotateSize,
                                   int maxBackupIndex)
                            throws java.io.FileNotFoundException

Construct a new instance with the given output file.

Parameters:
  `file` - the file
Throws:
  `java.io.FileNotFoundException` - if the file could not be found on open

#### SizeRotatingFileHandler

    public SizeRotatingFileHandler​(java.io.File file,
                                   boolean append,
                                   long rotateSize,
                                   int maxBackupIndex)
                            throws java.io.FileNotFoundException

Construct a new instance with the given output file and append setting.

Parameters:
  `file` - the file
  `append` - `true` to append, `false` to overwrite
Throws:
  `java.io.FileNotFoundException` - if the file could not be found on open

### Method Detail

#### setOutputStream

    public void setOutputStream​(java.io.OutputStream outputStream)

Set the output stream to write to.

Overrides:
  `setOutputStream` in class `OutputStreamHandler`
Parameters:
  `outputStream` - the new output stream or `null` for none

#### setFile

    public void setFile​(java.io.File file)
                 throws java.io.FileNotFoundException

Set the output file.

Overrides:
  `setFile` in class `FileHandler`
Parameters:
  `file` - the file
Throws:
  `java.lang.RuntimeException` - if there is an attempt to rotate file and the rotation fails
  `java.io.FileNotFoundException` - 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:
  `true` if file should rotate on boot, otherwise `false`/

#### setRotateOnBoot

    public void setRotateOnBoot​(boolean rotateOnBoot)

Set to a value of `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 `length` greater than 0.

Parameters:
  `rotateOnBoot` - `true` to rotate on boot, otherwise `false`

#### 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

    public java.lang.String getSuffix()

Returns the suffix set to be appended to files during rotation.

Returns:
  the suffix or `null` if no suffix should be used

#### setSuffix

    public void setSuffix​(java.lang.String suffix)

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 the `SimpleDateFormat`. Optionally the suffix can end with `.gz` or `.zip` which will compress the file on rotation.

If the suffix ends with `.gz` or `.zip` the file will be compressed on rotation.

Note: The `maxBackupIndex` only takes into account files rotated with same suffix. For example if the suffix pattern is `.yyyy-MM-dd` and the size rotation is reached only files with the same date suffix will be purged. A file the day before or after will not be purged.

Parameters:
  `suffix` - the suffix to place after the filename when the file is rotated

#### preWrite

    protected void preWrite​(ExtLogRecord record)

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:
  `preWrite` in class `WriterHandler`
Parameters:
  `record` - the record about to be logged