org.kaariboga.util
Class Log

java.lang.Object
  |
  +--org.kaariboga.util.Log

public class Log
extends java.lang.Object

Global handling of logging and error messages. This class is purely static. Don't create any instance of it. Just use it like: Log.write( Log.INFORMATION, "All is fine." ); This class supports the following log levels: ERROR, WARNING, SUCCESS, INFORMATION, DEBUG. On startup loglevel INFORMATION is active. Note, that all errors in this class are written to System.err. This prevents infinite loops.


Field Summary
protected static java.lang.String backupLogfile
          Name of the logfile backup
static int DEBUG
          Used to write a debug message for extended information
static int ERROR
          Used to write an error message
protected static java.text.SimpleDateFormat formatter
          date format
protected static boolean hasLogfile
          Is there a logfile to write to?
static int INFORMATION
          Used to write a normal status message
protected static java.lang.String lineSeparator
          OS dependent line separator
protected static java.lang.String logfile
          Name of the logfile
protected static int loglevel
          Logging requests are fullfilled up to this loglevel.
protected static long maxLogSize
          maximum size of the logfile in bytes, standard is 100000
static int NONE
          Loglevel, if no messages should be logged
protected static boolean standardOut
          should messages be written to standard output?
static int SUCCESS
          Used to write a success message.
static int WARNING
          Used to write an warning message
 
Constructor Summary
Log()
           
 
Method Summary
protected static void checkFileLength()
          Checks the length of the logfile.
static void setLog(java.lang.String log, java.lang.String back)
          Creates a new Log object that uses logfile as output.
static void setLoglevel(int level)
          Sets the loglevel of this Log.
static void setMaxLogSize(int size)
          Sets the maximum size of the logfile.
static void setStandardOutput(boolean flag)
          Determines if Java standard output should be used.
static void write(int status, java.lang.String message)
          Writes a logging message.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Loglevel, if no messages should be logged

ERROR

public static final int ERROR
Used to write an error message

WARNING

public static final int WARNING
Used to write an warning message

SUCCESS

public static final int SUCCESS
Used to write a success message. A success denotes an operation that has been fullfilled whithout any errors. This is usefull if you have a monitor that should display if the current status is error or success.

INFORMATION

public static final int INFORMATION
Used to write a normal status message

DEBUG

public static final int DEBUG
Used to write a debug message for extended information

logfile

protected static java.lang.String logfile
Name of the logfile

backupLogfile

protected static java.lang.String backupLogfile
Name of the logfile backup

maxLogSize

protected static long maxLogSize
maximum size of the logfile in bytes, standard is 100000

hasLogfile

protected static boolean hasLogfile
Is there a logfile to write to?

standardOut

protected static boolean standardOut
should messages be written to standard output?

loglevel

protected static int loglevel
Logging requests are fullfilled up to this loglevel.

lineSeparator

protected static java.lang.String lineSeparator
OS dependent line separator

formatter

protected static java.text.SimpleDateFormat formatter
date format
Constructor Detail

Log

public Log()
Method Detail

setLog

public static void setLog(java.lang.String log,
                          java.lang.String back)
Creates a new Log object that uses logfile as output. If one of the parameters is null, no logfiles will be written. Default is no logfiles.
Parameters:
log - Name of the logfile
back - Name as which the logfile should be stored, when it extends maximum size

setLoglevel

public static void setLoglevel(int level)
Sets the loglevel of this Log. This makes it possible to supress certain kinds of log messages.
Parameters:
level - Loglevel up to which the messages are logged. May have the following values: NONE if no messages should be displayed, ERROR for error messages, WARNING for wanrings that are not critical, SUCCESS if an operation has been successfully finished, INFORMATION for general information, DEBUG for extended debug information.

write

public static void write(int status,
                         java.lang.String message)
Writes a logging message.
Parameters:
status - Status of the message. May have the following values: ERROR for error messages, WARNING for wanrings that are not critical, SUCCESS if an operation has been successfully finished, INFORMATION for general information, DEBUG for extended debug information.
message - Text of the message.

setMaxLogSize

public static void setMaxLogSize(int size)
Sets the maximum size of the logfile. If the logfile exceeds the maximum size, the current log file is renamed and the Log creates a new one.
Parameters:
size - Maximum size of the logfile in KB

setStandardOutput

public static void setStandardOutput(boolean flag)
Determines if Java standard output should be used. Default value is true.
Parameters:
flag - True, if standard output should be used

checkFileLength

protected static void checkFileLength()
Checks the length of the logfile. If the logfile exeeds the specified maximum size, it deletes the old backup file and renames the current logfile to the backup file.