Log4j 1.1b7

org.apache.log4j
Class FileAppender

java.lang.Object
  |
  +--org.apache.log4j.AppenderSkeleton
        |
        +--org.apache.log4j.WriterAppender
              |
              +--org.apache.log4j.FileAppender
All Implemented Interfaces:
Appender, OptionHandler
Direct Known Subclasses:
DailyRollingFileAppender, RollingFileAppender

public class FileAppender
extends WriterAppender

FileAppender appends log events to a file. Support for java.io.Writer and console appending has been deprecated and will be removed in the near future. You are stongly encouraged to use the replacement solutions: WriterAppender and ConsoleAppender.

Author:
Ceki Gülcü

Field Summary
static String APPEND_OPTION
          Deprecated. We now use JavaBeans introspection to configure components. Options strings are no longer needed.
static String FILE_OPTION
          Deprecated. We now use JavaBeans introspection to configure components. Options strings are no longer needed.
protected  boolean fileAppend
          Append to or truncate the file?
protected  String fileName
          The name of the log file.
protected  boolean qwIsOurs
          Deprecated. FileAppender will not support streams passed by the user in the future.
 
Fields inherited from class org.apache.log4j.WriterAppender
IMMEDIATE_FLUSH_OPTION, immediateFlush, qw
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold, THRESHOLD_OPTION
 
Constructor Summary
FileAppender()
          The default constructor does not do anything.
FileAppender(Layout layout, OutputStream os)
          Deprecated. The functionality of this constructor form has been replaced by the WriterAppender. This constructor will be removed in the near term.
FileAppender(Layout layout, String filename)
          Instantiate a FileAppender and open the file designated by filename.
FileAppender(Layout layout, String filename, boolean append)
          Instantiate a FileAppender and open the file designated by filename.
FileAppender(Layout layout, Writer writer)
          Deprecated. The functionality of constructor form has been replaced by the WriterAppender. This constructor will be removed in the near term.
 
Method Summary
 void activateOptions()
          If the value of FILE_OPTION is not null, then setFile(java.lang.String) is called with the values of FILE_OPTION and APPEND_OPTION.
protected  void closeFile()
          Closes the previously opened file.
 boolean getAppend()
          Returns the value of the Append option.
 String getFile()
          Returns the value of the File option.
 String[] getOptionStrings()
          Deprecated. We now use JavaBeans introspection to configure components. Options strings are no longer needed.
protected  void reset()
          Close any previously opened file and call the parent's reset.
 void setAppend(boolean flag)
          Append option takes a boolean value.
 void setFile(String file)
          The File option takes a string value which should be the name of the file to append to.
 void setFile(String fileName, boolean append)
          Sets and opens the file where the log output will go.
 void setOption(String key, String value)
          Set option to value.
protected  void setQWForFiles(Writer writer)
          Sets the quiet writer being used.
 
Methods inherited from class org.apache.log4j.WriterAppender
append, checkEntryConditions, close, closeWriter, getImmediateFlush, requiresLayout, setErrorHandler, setImmediateFlush, setWriter, subAppend, writeFooter, writeHeader
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_OPTION

public static final String FILE_OPTION
Deprecated. We now use JavaBeans introspection to configure components. Options strings are no longer needed.

A string constant used in naming the option for setting the output file. Current value of this string constant is File.

Note that all option keys are case sensitive.


APPEND_OPTION

public static final String APPEND_OPTION
Deprecated. We now use JavaBeans introspection to configure components. Options strings are no longer needed.

A string constant used in naming the option that determines whether the output file will be truncated or appended to. Current value of this string constant is Append.

Note that all option keys are case sensitive.


fileAppend

protected boolean fileAppend
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.

This option is meaningful only if the FileAppender opens the file.


fileName

protected String fileName
The name of the log file.

qwIsOurs

protected boolean qwIsOurs
Deprecated. FileAppender will not support streams passed by the user in the future.

Is the QuietWriter ours or was it created and passed by the user?
Constructor Detail

FileAppender

public FileAppender()
The default constructor does not do anything.

FileAppender

public FileAppender(Layout layout,
                    OutputStream os)
Deprecated. The functionality of this constructor form has been replaced by the WriterAppender. This constructor will be removed in the near term.

Instantiate a FileAppender and set the output destination to a new OutputStreamWriter initialized with os as its OutputStream.

FileAppender

public FileAppender(Layout layout,
                    Writer writer)
Deprecated. The functionality of constructor form has been replaced by the WriterAppender. This constructor will be removed in the near term.

Instantiate a FileAppender and set the output destination to writer.

The writer must have been opened by the user.


FileAppender

public FileAppender(Layout layout,
                    String filename,
                    boolean append)
             throws IOException
Instantiate a FileAppender and open the file designated by filename. The opened filename will become the ouput destination for this appender.

If the append parameter is true, the file will be appended to. Otherwise, the file designated by filename will be truncated before being opened.


FileAppender

public FileAppender(Layout layout,
                    String filename)
             throws IOException
Instantiate a FileAppender and open the file designated by filename. The opened filename will become the output destination for this appender.

The file will be appended to.

Method Detail

setFile

public void setFile(String file)
The File option takes a string value which should be the name of the file to append to. Special values "System.out" or "System.err" are interpreted as the standard out and standard error streams.

Note that the "System.out" or "System.err" options are deprecated. Use ConsoleAppender instead.

If the option is set to "System.out" or "System.err" the output will go to the corresponding stream. Otherwise, if the option is set to the name of a file, then the file will be opened and output will go there.

Note: Actual opening of the file is made when activateOptions() is called, not when the options are set.


getAppend

public boolean getAppend()
Returns the value of the Append option.

getFile

public String getFile()
Returns the value of the File option.

getOptionStrings

public String[] getOptionStrings()
Deprecated. We now use JavaBeans introspection to configure components. Options strings are no longer needed.

Returns the option names for this component, namely the string array FILE_OPTION, APPEND_OPTION} in addition to the options of its super class WriterAppender.
Overrides:
getOptionStrings in class WriterAppender

setAppend

public void setAppend(boolean flag)
Append option takes a boolean value. It is set to true by default. If true, then File will be opened in append mode by setFile (see above). Otherwise, setFile will open File in truncate mode.

Note: Actual opening of the file is made when activateOptions() is called, not when the options are set.


activateOptions

public void activateOptions()
If the value of FILE_OPTION is not null, then setFile(java.lang.String) is called with the values of FILE_OPTION and APPEND_OPTION.
Overrides:
activateOptions in class WriterAppender
Since:
0.8.1

closeFile

protected void closeFile()
Closes the previously opened file.

setFile

public void setFile(String fileName,
                    boolean append)
             throws 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.

Parameters:
fileName - The path to the log file.
append - If true will append to fileName. Otherwise will truncate fileName.

setOption

public void setOption(String key,
                      String value)
Deprecated. Use the setter method for the option directly instead of the generic setOption method.

Description copied from interface: OptionHandler
Set option to value.

The handling of each option depends on the OptionHandler instance. Some options may become active immediately whereas other may be activated only when OptionHandler.activateOptions() is called.

Overrides:
setOption in class WriterAppender

setQWForFiles

protected void setQWForFiles(Writer writer)
Sets the quiet writer being used. This method is overriden by RollingFileAppender.

reset

protected void reset()
Close any previously opened file and call the parent's reset.
Overrides:
reset in class WriterAppender

Log4j 1.1b7

Please notify me about new log4j releases.