uk.ac.ic.doc.automed.util
Class LogOutputHandler

java.lang.Object
  extended by uk.ac.ic.doc.automed.util.LogOutputHandler

public class LogOutputHandler
extends java.lang.Object

LogOutputHandler.java

Author:
Duc M Le dmle@doc.ic.ac.uk Created on 01 August 2006 Department of Computing, Imperial College

Field Summary
private  boolean _append
           
private  java.io.ByteArrayOutputStream _bout
           
private  java.io.PrintStream _console
           
private  java.io.FileWriter _errFile
           
private  long _errLogFileSize
           
private  java.io.FileWriter _file
           
private  int _handlerType
          the handler type
private  long _logFileSize
           
private  java.io.PrintWriter _peFile
           
private  java.io.PrintWriter _pFile
           
static int CONSOLE
          Print log messages to std output only
static java.lang.String ERROR_LOG_FILE
           
static int FILE
          Print log messages to file
static java.lang.String LOG_FILE
           
private static long MAX_ERROR_LOG_SIZE
           
private static long MAX_LOG_SIZE
           
static int MEMORY
          Print log messages to a given byte array
static int REMOTE
          Print log messages to a log server
 
Constructor Summary
LogOutputHandler(int handlerType)
          Creates a new instance of LogHandler Set default value of append to true
LogOutputHandler(int handlerType, boolean append)
          Creates a new instance of LogHandler
 
Method Summary
private  void createWriters(java.lang.String file)
          Prepare writers
 java.io.PrintStream getConsole()
           
protected  int getHandlerType()
          return the log handler type
private  java.lang.String getLogString(java.lang.String[] logElements)
          Format a record log for writing
 java.lang.String getMemoryLog()
          Only used when log handler type is set to MEMORY
static void main(java.lang.String[] args)
           
private  void monitorFile(java.lang.String file)
          Check if file sizes have grown over the limits
 void output(java.lang.String[] logElements)
          Write log message to normal log file.
private  void outputConsole(java.lang.String ls, java.lang.Throwable t)
           
 void outputError(java.lang.String[] logElements, java.lang.Throwable t)
          Write errors to error log file.
private  void readInitSizes()
          Read file sizes
 void setConsole(java.io.PrintStream ps)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_handlerType

private int _handlerType
the handler type


CONSOLE

public static final int CONSOLE
Print log messages to std output only

See Also:
Constant Field Values

FILE

public static final int FILE
Print log messages to file

See Also:
Constant Field Values

REMOTE

public static final int REMOTE
Print log messages to a log server

See Also:
Constant Field Values

MEMORY

public static final int MEMORY
Print log messages to a given byte array

See Also:
Constant Field Values

LOG_FILE

public static final java.lang.String LOG_FILE

ERROR_LOG_FILE

public static final java.lang.String ERROR_LOG_FILE

MAX_LOG_SIZE

private static final long MAX_LOG_SIZE
See Also:
Constant Field Values

MAX_ERROR_LOG_SIZE

private static final long MAX_ERROR_LOG_SIZE
See Also:
Constant Field Values

_console

private java.io.PrintStream _console

_file

private java.io.FileWriter _file

_errFile

private java.io.FileWriter _errFile

_pFile

private java.io.PrintWriter _pFile

_peFile

private java.io.PrintWriter _peFile

_append

private boolean _append

_bout

private java.io.ByteArrayOutputStream _bout

_logFileSize

private long _logFileSize

_errLogFileSize

private long _errLogFileSize
Constructor Detail

LogOutputHandler

public LogOutputHandler(int handlerType)
Creates a new instance of LogHandler Set default value of append to true


LogOutputHandler

public LogOutputHandler(int handlerType,
                        boolean append)
Creates a new instance of LogHandler

Method Detail

setConsole

public void setConsole(java.io.PrintStream ps)

getConsole

public java.io.PrintStream getConsole()

readInitSizes

private void readInitSizes()
Read file sizes


createWriters

private void createWriters(java.lang.String file)
                    throws java.io.IOException
Prepare writers

Throws:
java.io.IOException

monitorFile

private void monitorFile(java.lang.String file)
Check if file sizes have grown over the limits


output

public void output(java.lang.String[] logElements)
Write log message to normal log file. It also monitors the file's growth.


outputError

public void outputError(java.lang.String[] logElements,
                        java.lang.Throwable t)
Write errors to error log file. It also monitors the file's growth.


getMemoryLog

public java.lang.String getMemoryLog()
Only used when log handler type is set to MEMORY


outputConsole

private void outputConsole(java.lang.String ls,
                           java.lang.Throwable t)

getLogString

private java.lang.String getLogString(java.lang.String[] logElements)
Format a record log for writing


getHandlerType

protected int getHandlerType()
return the log handler type


main

public static void main(java.lang.String[] args)