org.jboss.logging.jdk.handlers
Class FileHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by org.jboss.logging.jdk.handlers.HandlerSkeleton
          extended by org.jboss.logging.jdk.handlers.WriterHandler
              extended by org.jboss.logging.jdk.handlers.FileHandler
Direct Known Subclasses:
DailyRollingFileHandler

public class FileHandler
extends WriterHandler

FileAppender appends log events to a file.

Version:
$Revision: 1.2 $
Author:
Ceki Gülcü, Scott.Stark@jboss.org

Field Summary
protected  boolean fileAppend
          Controls file truncatation.
protected  String fileName
          The name of the log file.
 
Fields inherited from class org.jboss.logging.jdk.handlers.WriterHandler
bufferedIO, bufferSize, immediateFlush
 
Fields inherited from class org.jboss.logging.jdk.handlers.HandlerSkeleton
name
 
Constructor Summary
FileHandler()
          The default constructor does not do anything.
FileHandler(Formatter layout, String filename)
          Instantiate a FileHandler and open the file designated by filename.
FileHandler(Formatter layout, String filename, boolean append)
          Instantiate a FileHandler and open the file designated by filename.
FileHandler(Formatter layout, String filename, boolean append, boolean bufferedIO, int bufferSize)
          Instantiate a FileHandler and open the file designated by filename.
 
Method Summary
 void activateOptions()
          If the value of File is not null, then setFile(java.lang.String) is called with the values of File and Append properties.
 boolean getAppend()
          Returns the value of the Append option.
 String getFile()
          Returns the value of the File option.
 void setAppend(boolean flag)
          The Append option takes a boolean value.
 void setFile(String file)
          The File property takes a string value which should be the name of the file to append to.
 void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize)
          Sets and opens the file where the log output will go.
 
Methods inherited from class org.jboss.logging.jdk.handlers.WriterHandler
checkEntryConditions, close, flush, getBufferSize, getImmediateFlush, isBufferedIO, publish, setBufferedIO, setBufferSize, setEncoding, setImmediateFlush, setOutputStream, subPublish
 
Methods inherited from class org.jboss.logging.jdk.handlers.HandlerSkeleton
debug, getName, setName
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileAppend

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

Constructor Detail

FileHandler

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


FileHandler

public FileHandler(Formatter layout,
                   String filename,
                   boolean append,
                   boolean bufferedIO,
                   int bufferSize)
            throws IOException
Instantiate a FileHandler and open the file designated by filename. The opened filename will become the output 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.

If the bufferedIO parameter is true, then buffered IO will be used to write to the output file.

Throws:
IOException

FileHandler

public FileHandler(Formatter layout,
                   String filename,
                   boolean append)
            throws IOException
Instantiate a FileHandler and open the file designated by filename. The opened filename will become the output 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.

Throws:
IOException

FileHandler

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

The file will be appended to.

Throws:
IOException
Method Detail

setFile

public void setFile(String file)
The File property takes a string value which should be the name of the file to append to.

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.


activateOptions

public void activateOptions()
If the value of File is not null, then setFile(java.lang.String) is called with the values of File and Append properties.

Overrides:
activateOptions in class HandlerSkeleton

setAppend

public void setAppend(boolean flag)
The 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.


setFile

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

Do not use this method directly. To configure a FileHandler or one of its subclasses, set its properties one by one and then call activateOptions.

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


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.