JCas
v0.3.1

cas.util
Class Logger

java.lang.Object
  extended byjava.io.OutputStream
      extended bycas.util.Logger

public class Logger
extends OutputStream

Implements logging functionality. The messages are displayed on standard output by default. Additionally, they can be replicated to a logfile.

Version:
1.0
Author:
Ralph Schuster

Field Summary
protected static Date currentTime
           
static int ERROR
           
protected static SimpleDateFormat formatter
           
static int INFO
           
protected static File logfile
           
protected static int loglevel
           
protected static cas.util.Logger.MyPrintWriter logwriter
           
static int TRACE
           
 
Constructor Summary
Logger()
           
 
Method Summary
static void closeLog()
          Closes the log.
protected static void closeWriter(cas.util.Logger.MyPrintWriter writer)
          Closes the log stream if it is not the standard out or default logfile.
static void debug(String label, Object o)
          Prints debugging information.
protected static String getDate()
          Returns the formatted, current date and time.
static int getLogLevel()
          Returns the log level.
protected static cas.util.Logger.MyPrintWriter getWriter(File f)
          Returns the correct writer.
static void log(Object o)
          Logs an object with its toString() method.
static void log(Object src, String s)
          Logs the string marked wih the specified object as the message source.
static void log(Object src, String s, int level, File logfile)
          Logs the message issued by the source with the specified log level.
static void log(String s)
          Logs a message.
static void log(String s, File logfile)
          Logs a message to a specific file.
static void log(String s, int level)
          Logs a message with the specified log level.
static void log(String s, int level, File logfile)
          Logs a message with the specified log level to a specific file.
static void log(Throwable e)
          Logs the exception.
static void log(Throwable e, File logfile)
          Logs the exception to a specific logfile.
static void log(Throwable e, int level, File logfile)
          Logs the exception with the specified log level.
static void logArray(Object[] o)
          Logs the string array.
static void setLogfile(File f)
          Sets the logfile.
static void setLogfile(String s)
          Sets the logfile.
static void setLogLevel(int l)
          Sets the loglevel.
 void write(int b)
          Implementation of the OutputStream methods.
 
Methods inherited from class java.io.OutputStream
close, flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR

public static final int ERROR
See Also:
Constant Field Values

INFO

public static final int INFO
See Also:
Constant Field Values

TRACE

public static final int TRACE
See Also:
Constant Field Values

logfile

protected static File logfile

loglevel

protected static int loglevel

logwriter

protected static cas.util.Logger.MyPrintWriter logwriter

currentTime

protected static Date currentTime

formatter

protected static SimpleDateFormat formatter
Constructor Detail

Logger

public Logger()
Method Detail

setLogfile

public static void setLogfile(String s)
Sets the logfile.

Parameters:
s - the filename (can be null)

setLogfile

public static void setLogfile(File f)
Sets the logfile.

Parameters:
f - the file (can be null)

setLogLevel

public static void setLogLevel(int l)
Sets the loglevel.

Parameters:
l - loglevel between 0 and 2 (including).

getLogLevel

public static int getLogLevel()
Returns the log level.


log

public static void log(Object src,
                       String s)
Logs the string marked wih the specified object as the message source.


log

public static void log(Object o)
Logs an object with its toString() method.


log

public static void log(String s)
Logs a message.


log

public static void log(String s,
                       File logfile)
Logs a message to a specific file.


log

public static void log(String s,
                       int level)
Logs a message with the specified log level.


log

public static void log(String s,
                       int level,
                       File logfile)
Logs a message with the specified log level to a specific file.


getWriter

protected static cas.util.Logger.MyPrintWriter getWriter(File f)
Returns the correct writer. Basically the method checks if the logfile is equal to the default logfile and returns the appropriate writer then. Otherwise the method returns the System.out stream or a specific writer for the logfile.


closeWriter

protected static void closeWriter(cas.util.Logger.MyPrintWriter writer)
Closes the log stream if it is not the standard out or default logfile.


log

public static void log(Object src,
                       String s,
                       int level,
                       File logfile)
Logs the message issued by the source with the specified log level.


log

public static void log(Throwable e)
Logs the exception.


log

public static void log(Throwable e,
                       File logfile)
Logs the exception to a specific logfile.


log

public static void log(Throwable e,
                       int level,
                       File logfile)
Logs the exception with the specified log level.


debug

public static void debug(String label,
                         Object o)
Prints debugging information.

Parameters:
label - a string to display
o - the object to be printed

closeLog

public static void closeLog()
Closes the log.


getDate

protected static String getDate()
Returns the formatted, current date and time.


write

public void write(int b)
           throws IOException
Implementation of the OutputStream methods.

Throws:
IOException

logArray

public static void logArray(Object[] o)
Logs the string array.


JCas
v0.3.1