gecco.server.core
Class LogManager

java.lang.Object
  |
  +--gecco.server.core.LogManager

public class LogManager
extends Object

This class manages the log, and exports methods that make it possible to write to the log.

Author:
Henrik Bäärnhielm, Karl Hasselström, Henrik Hägerström.

Field Summary
protected  SimpleDateFormat formatter
          The formatter for the dates in the log.
protected  PrintWriter stream
          The stream of the log file.
 
Constructor Summary
LogManager(String filename)
          Constructor for the LogManager object.
LogManager(String filename, boolean autoFlush)
          Constructor for the LogManager object
 
Method Summary
 void debug(String message)
          Outputs a debug message to the log file.
 void flush()
          Flushes the log file.
 void log(String message)
          Outputs a log message to the log file.
protected  void printMessage(String header, String message)
          Prints a message to the log file, with a header and the current date and time.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

stream

protected PrintWriter stream
The stream of the log file.

formatter

protected SimpleDateFormat formatter
The formatter for the dates in the log.
Constructor Detail

LogManager

public LogManager(String filename,
                  boolean autoFlush)
           throws IOException
Constructor for the LogManager object
Parameters:
filename - The name of the log file.
autoFlush - Flag to indicate if the log should be flushed after each line.
Throws:
IOException - Throws an IOException if the log file could not be opened.

LogManager

public LogManager(String filename)
           throws IOException
Constructor for the LogManager object. This does not use autoflushing after each line.
Parameters:
filename - The name of the log file.
Throws:
IOException - Throws an IOException if the log file could not be opened.
Method Detail

log

public void log(String message)
Outputs a log message to the log file.
Parameters:
message - The log message.

debug

public void debug(String message)
Outputs a debug message to the log file.
Parameters:
message - The debug message.

flush

public void flush()
Flushes the log file. This should be called periodically if autoflush is not used, else there might be risk of losing data.

printMessage

protected void printMessage(String header,
                            String message)
Prints a message to the log file, with a header and the current date and time.
Parameters:
header - Header of the message.
message - Message text.