QJCC homepage

biz.chitec.quarterback.util
Class LogFileWriter

java.lang.Object
  extended bybiz.chitec.quarterback.util.LogFileWriter
All Implemented Interfaces:
LoggingReceiver

public class LogFileWriter
extends java.lang.Object
implements LoggingReceiver

Log object which can write into file and onto console. Standard stream logging is possible. LogFileWriter takes an object in its handleLogObject method and writes it somewhere. Normally, the object is written onto the console. If is, however, possible to use a log file where the object is written, too.

Through the static methods open/closeStandardStreamsLogFileWriter() any output to the standard streams can be passed through a LogFileWriter object. This way, it is possible to log standard output, e.g. Exception stack traces, into a file. If a Throwable object is thrown directly into the LogFileWriter, it tries to obtain and log its stack trace automatically.

This receiver is hardcoded not to write more than the first 500 characters of each line of the message to be logged.

Version:
$Id: 96a33caa8208b98273f39e5b02e92c8b938bf2a0 $
Author:
Dirk Hillbrecht 1998-2000, chitec/Dirk Hillbrecht 2000, cantamen/Dirk Hillbrecht 2004. Distributed under the terms of the GNU LGPL.

Nested Class Summary
(package private) static class LogFileWriter.StandardStreamLogger
           
 
Field Summary
(package private)  boolean consoleout
           
(package private)  boolean filelogging
           
(package private)  java.lang.String filename
           
(package private)  java.io.PrintWriter fileout
           
(package private) static java.io.PrintStream newstd
           
(package private)  java.lang.String oldnowstring
           
(package private) static java.io.PrintStream oldstderr
           
(package private) static java.io.PrintStream oldstdout
           
(package private) static LogFileWriter.StandardStreamLogger ssl
           
(package private) static LogFileWriter stdholder
           
 
Constructor Summary
LogFileWriter()
           
 
Method Summary
 void close()
           
 void closeOutputFile()
           
static void closeStandardStreamsLogFileWriter()
           
protected  void finalize()
           
 boolean getConsoleOut()
           
 boolean getFileLogging()
           
 java.lang.String getFilename()
           
 void handleLogObject(Logger src, java.lang.Object o)
          logging receiving method.
 void openOutputFile()
           
static LogFileWriter openStandardStreamsLogFileWriter()
           
 void setConsoleOut(boolean co)
           
 void setFileLogging(boolean fl)
           
 void setFilename(java.lang.String fn)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oldstdout

static java.io.PrintStream oldstdout

oldstderr

static java.io.PrintStream oldstderr

stdholder

static LogFileWriter stdholder

ssl

static LogFileWriter.StandardStreamLogger ssl

newstd

static java.io.PrintStream newstd

consoleout

boolean consoleout

filelogging

boolean filelogging

filename

java.lang.String filename

fileout

java.io.PrintWriter fileout

oldnowstring

java.lang.String oldnowstring
Constructor Detail

LogFileWriter

public LogFileWriter()
Method Detail

close

public void close()

finalize

protected void finalize()
                 throws java.io.IOException
Throws:
java.io.IOException

setConsoleOut

public void setConsoleOut(boolean co)

getConsoleOut

public boolean getConsoleOut()

setFileLogging

public void setFileLogging(boolean fl)

getFileLogging

public boolean getFileLogging()

setFilename

public void setFilename(java.lang.String fn)

getFilename

public java.lang.String getFilename()

closeOutputFile

public void closeOutputFile()
                     throws java.io.IOException
Throws:
java.io.IOException

openOutputFile

public void openOutputFile()
                    throws java.io.IOException
Throws:
java.io.IOException

handleLogObject

public void handleLogObject(Logger src,
                            java.lang.Object o)
Description copied from interface: LoggingReceiver
logging receiving method.

Specified by:
handleLogObject in interface LoggingReceiver

openStandardStreamsLogFileWriter

public static LogFileWriter openStandardStreamsLogFileWriter()
                                                      throws java.io.IOException
Throws:
java.io.IOException

closeStandardStreamsLogFileWriter

public static void closeStandardStreamsLogFileWriter()

QJCC homepage