Package ch.qos.logback.core

## Class FileAppender<E>

- java.lang.Object
- - ch.qos.logback.core.spi.ContextAwareBase
  - - ch.qos.logback.core.UnsynchronizedAppenderBase<E>
    - - ch.qos.logback.core.OutputStreamAppender<E>
      - - ch.qos.logback.core.FileAppender<E>

All Implemented Interfaces:
  `Appender<E>`, `ContextAware`, `FilterAttachable<E>`, `LifeCycle`

Direct Known Subclasses:
  `RollingFileAppender`

    public class FileAppender<E>
    extends OutputStreamAppender<E>

FileAppender appends log events to a file. For more information about this appender, please refer to the online manual at http://logback.qos.ch/manual/appenders.html#FileAppender

Author:
  Ceki Gülcü

### Field Summary

Fields
`protected boolean` `append` Append to or truncate the file? The default value for this variable is `true`, meaning that by default a `FileAppender` will append to an existing file and not truncate it.
`protected static java.lang.String` `COLLISION_WITH_EARLIER_APPENDER_URL`
`static long` `DEFAULT_BUFFER_SIZE`
`protected java.lang.String` `fileName` The name of the active log file.

### Fields inherited from class ch.qos.logback.core.OutputStreamAppender

`encoder, lock`

### Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase

`name, started`

### Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

`context`

### Constructor Summary

Constructors
`FileAppender()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addErrorForCollision​(java.lang.String optionName, java.lang.String optionValue, java.lang.String appenderName)`
`protected boolean` `checkForFileCollisionInPreviousFileAppenders()`
`java.lang.String` `getFile()` Returns the value of the File property.
`boolean` `isAppend()` Returns the value of the Append property.
`boolean` `isPrudent()`
`void` `openFile​(java.lang.String file_name)` Sets and opens the file where the log output will go.
`java.lang.String` `rawFileProperty()` This method is used by derived classes to obtain the raw file property.
`void` `setAppend​(boolean append)`
`void` `setBufferSize​(FileSize bufferSize)`
`void` `setFile​(java.lang.String file)` The File property takes a string value which should be the name of the file to append to.
`void` `setPrudent​(boolean prudent)` When prudent is set to true, file appenders from multiple JVMs can safely write to the same file.
`void` `start()` If the value of File is not `null`, then `openFile(java.lang.String)` is called with the values of File and Append properties.
`void` `stop()` Stop this appender instance.
`protected void` `writeOut​(E event)`

### Methods inherited from class ch.qos.logback.core.OutputStreamAppender

`append, closeOutputStream, getEncoder, getOutputStream, isImmediateFlush, setEncoder, setImmediateFlush, setLayout, setOutputStream, subAppend`

### Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase

`addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString`

### Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase

`addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext`

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

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

### Methods inherited from interface ch.qos.logback.core.spi.ContextAware

`addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext`

### Field Detail

#### DEFAULT_BUFFER_SIZE

    public static final long DEFAULT_BUFFER_SIZE

See Also:
  Constant Field Values

#### COLLISION_WITH_EARLIER_APPENDER_URL

    protected static java.lang.String COLLISION_WITH_EARLIER_APPENDER_URL

#### append

    protected boolean append

Append to or truncate the file? The default value for this variable is `true`, meaning that by default a `FileAppender` will append to an existing file and not truncate it.

#### fileName

    protected java.lang.String fileName

The name of the active log file.

### Constructor Detail

#### FileAppender

    public FileAppender()

### Method Detail

#### setFile

    public void setFile​(java.lang.String file)

The File property takes a string value which should be the name of the file to append to.

#### isAppend

    public boolean isAppend()

Returns the value of the Append property.

#### rawFileProperty

    public final java.lang.String rawFileProperty()

This method is used by derived classes to obtain the raw file property. Regular users should not be calling this method.

Returns:
  the value of the file property

#### getFile

    public java.lang.String getFile()

Returns the value of the File property.

This method may be overridden by derived classes.

#### start

    public void start()

If the value of File is not `null`, then `openFile(java.lang.String)` is called with the values of File and Append properties.

Specified by:
  `start` in interface `LifeCycle`
Overrides:
  `start` in class `OutputStreamAppender<E>`

#### stop

    public void stop()

Description copied from class: `OutputStreamAppender`
Stop this appender instance. The underlying stream or writer is also closed.

Stopped appenders cannot be reused.

Specified by:
  `stop` in interface `LifeCycle`
Overrides:
  `stop` in class `OutputStreamAppender<E>`

#### checkForFileCollisionInPreviousFileAppenders

    protected boolean checkForFileCollisionInPreviousFileAppenders()

#### addErrorForCollision

    protected void addErrorForCollision​(java.lang.String optionName,
                                        java.lang.String optionValue,
                                        java.lang.String appenderName)

#### openFile

    public void openFile​(java.lang.String file_name)
                  throws java.io.IOException

Sets and opens the file where the log output will go. The specified file must be writable.

If there was already an opened file, then the previous file is closed first.

Do not use this method directly. To configure a FileAppender or one of its subclasses, set its properties one by one and then call start().

Parameters:
  `file_name` - The path to the log file.
Throws:
  `java.io.IOException`

#### isPrudent

    public boolean isPrudent()

Returns:
  true if in prudent mode
See Also:
  `setPrudent(boolean)`

#### setPrudent

    public void setPrudent​(boolean prudent)

When prudent is set to true, file appenders from multiple JVMs can safely write to the same file.

Parameters:
  `prudent` -

#### setAppend

    public void setAppend​(boolean append)

#### setBufferSize

    public void setBufferSize​(FileSize bufferSize)

#### writeOut

    protected void writeOut​(E event)
                     throws java.io.IOException

Overrides:
  `writeOut` in class `OutputStreamAppender<E>`
Throws:
  `java.io.IOException`