uk.org.iscream.cms.server.core.loggers
Class FileLogger

java.lang.Object
  extended byuk.org.iscream.cms.server.core.loggers.FileLogger
All Implemented Interfaces:
LoggerImpl

public class FileLogger
extends Object
implements LoggerImpl

The FileLogger is an implementation of the LoggerImpl defined in the associated interface. It provides quite extensive features to allow logging ot a text file.

Version:
$Id: FileLogger.java,v 1.13 2004/08/01 10:40:56 tdb Exp $
Author:
$Author: tdb $

Field Summary
private  String _name
          This is the friendly identifier of the component this class is running in.
private  String filename
          The filename of the currently open, or last open, file.
private  boolean open
          A boolean signifying whether a file is open or not.
 String REVISION
          The current CVS revision of this class
private  BufferedWriter writer
          A reference to the writer being used.
 
Constructor Summary
FileLogger()
          Creates a new FileLogger.
 
Method Summary
 void clear()
          The clear() method erases the contents of the logfile.
 void close()
          The close() method closes the logfile and no more data can be written.
private  boolean fileCheck()
          The fileCheck() method is used to ensure that writing is ok.
 void open(String filename)
          The open() method opens a new file after the close() method has been called on the FileLog.
 void resume()
          The resume() method resumes writing to the file by setting the open boolean to true.
 void suspend()
          The suspend() method halts writing to the file by setting the open boolean to false, and thus blocking the write() method.
 String toString()
          Overrides the Object.toString() method to provide clean logging (every class should have this).
 void write(String line, int verbosity)
          The write() method takes a line of text, pre-formatted and outputs it using a method defined by the actual implementation.
private  void write(String source, int verbosity, String message)
          This method is provided if this class wishes to log a message itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

filename

private String filename
The filename of the currently open, or last open, file.


writer

private BufferedWriter writer
A reference to the writer being used.


open

private boolean open
A boolean signifying whether a file is open or not.


_name

private String _name
This is the friendly identifier of the component this class is running in. eg, a Filter may be called "filter1", If this class does not have an owning component, a name from the configuration can be placed here. This name could also be changed to null for utility classes.

Constructor Detail

FileLogger

public FileLogger()
           throws IOException
Creates a new FileLogger. The constructor checks that writing will be ok, then sets up the writer. It makes use of the fileCheck() method found later on to ensure writing will be ok, and throws an IOException if there is a problem. Errors at this stage cannot be logged because the logging mechanism has not be setup completely, so any problems are printed to the screen in the same format used for logging.

Throws:
IOException - if there is a problem with the file check.
Method Detail

write

public void write(String line,
                  int verbosity)
The write() method takes a line of text, pre-formatted and outputs it using a method defined by the actual implementation. The verbosity is given in case the implementation wishes to utilise it in the layout - eg. a different colour or font. This instance writes the line to a file.

Specified by:
write in interface LoggerImpl
Parameters:
line - A line of formatted text to be logged
verbosity - the verbosity of this message

clear

public void clear()
The clear() method erases the contents of the logfile. It does this in a very clumsy way - by closing the writer and opening a new one which is set not to append. This results in the logfile being overwritten, which effectively erases it.


close

public void close()
The close() method closes the logfile and no more data can be written. If writing is attempted after close() has been called an error will be generated. The open() method can be used to reopen or open a new file.


open

public void open(String filename)
          throws IOException
The open() method opens a new file after the close() method has been called on the FileLog. This enables the user to easily change the file to which the log is being written. An error is generated if a file is already open.

Parameters:
filename - The new file to write to.
Throws:
IOException - if the file cannot be written to.

suspend

public void suspend()
The suspend() method halts writing to the file by setting the open boolean to false, and thus blocking the write() method. A line is written to the logfile beforehand to note that writing has been suspended.


resume

public void resume()
The resume() method resumes writing to the file by setting the open boolean to true. A line is written to the logfile to signify this event occuring.


toString

public String toString()
Overrides the Object.toString() method to provide clean logging (every class should have this). This uses the uk.org.iscream.cms.util.FormatName class to format the toString()

Returns:
the name of this class and its CVS revision

fileCheck

private boolean fileCheck()
The fileCheck() method is used to ensure that writing is ok. It performs so basic checks to make sure that if the file exists it can be written to, and if not a new file is created. A boolean result is returned to signify success or failure.

Returns:
A boolean value signify whether the test was sucessful.

write

private void write(String source,
                   int verbosity,
                   String message)
This method is provided if this class wishes to log a message itself.

Parameters:
source - A String representation of the source
verbosity - the verbosity of this message
message - The message to log


Copyright © 2000-2003 i-scream. All Rights Reserved.