com.groiss.log
Class Logger

java.lang.Object
  extended by com.groiss.log.Logger
All Implemented Interfaces:
Service, ILogger

public class Logger
extends java.lang.Object
implements ILogger

Default implementation of the ILogger interface.


Field Summary
protected static java.io.PrintWriter err
           
protected static java.util.Date errdate
           
protected static java.io.File errfile
           
protected static long errs
           
protected static java.lang.String linesep
           
protected static java.io.PrintWriter log
           
protected static java.io.File logfile
           
protected static int trace
           
 
Constructor Summary
Logger()
           
Logger(java.io.PrintWriter logger, int traceLevel)
           
 
Method Summary
 java.io.File getErrorLogFile()
          The file where errors are logged, if errors are logged to a separate file.
 long getExceptionCount()
          Return the number of exceptions since startup
 java.util.Date getLastExceptionDate()
          Return the date when the last exception has occured
 int getLevel()
          Returns the log level.
 java.io.File getLogFile()
          Return the Reader to read the current log file.
protected  java.lang.String getLogPrefix(int level)
          Returns the prefix of a log entry (which is the part before the specific log message).
 java.io.PrintWriter getWriter()
          Return the Writer to write some stuff to the log file.
 boolean isRunning()
           
 void log(java.lang.String str)
          This method writes the given string into the logfile.
 void log(java.lang.String str, int level)
          This method writes the given string into the logfile.
 void logError(java.lang.Throwable e)
          Prints a header line and a stack trace for the given Error or Exception
 void logError(java.lang.Throwable error, java.lang.String errHeader)
          Prints a header line and a stack trace for the given Error or Exception
 void logError(java.lang.Throwable error, java.lang.String errHeader, int level)
          Prints a header line and a stack trace for the given Error or Exception
 void reconfigure()
           
 void restart()
          Restart the Logger (reinitialize log file)
 void shutdown()
           
 void startup()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static java.io.PrintWriter log

err

protected static java.io.PrintWriter err

logfile

protected static java.io.File logfile

errfile

protected static java.io.File errfile

trace

protected static int trace

errs

protected static long errs

errdate

protected static java.util.Date errdate

linesep

protected static java.lang.String linesep
Constructor Detail

Logger

public Logger()

Logger

public Logger(java.io.PrintWriter logger,
              int traceLevel)
Method Detail

shutdown

public void shutdown()
              throws ApplicationException
Specified by:
shutdown in interface Service
Throws:
ApplicationException

isRunning

public boolean isRunning()
                  throws ApplicationException
Specified by:
isRunning in interface Service
Throws:
ApplicationException

reconfigure

public void reconfigure()
                 throws ApplicationException
Specified by:
reconfigure in interface Service
Throws:
ApplicationException

startup

public void startup()
             throws ApplicationException
Specified by:
startup in interface Service
Throws:
ApplicationException

log

public void log(java.lang.String str)
This method writes the given string into the logfile.

Parameters:
str - string to put into the logfile

log

public void log(java.lang.String str,
                int level)
This method writes the given string into the logfile. depending on the log level

Specified by:
log in interface ILogger
Parameters:
str - string to put into the logfile
level - the log level, an integer between 0 and 4

logError

public void logError(java.lang.Throwable e)
Prints a header line and a stack trace for the given Error or Exception

Specified by:
logError in interface ILogger

logError

public void logError(java.lang.Throwable error,
                     java.lang.String errHeader)
Prints a header line and a stack trace for the given Error or Exception

Specified by:
logError in interface ILogger
Parameters:
error - a Throwable object
errHeader - the text for the header line

logError

public void logError(java.lang.Throwable error,
                     java.lang.String errHeader,
                     int level)
Prints a header line and a stack trace for the given Error or Exception

Specified by:
logError in interface ILogger
Parameters:
error - a Throwable object
errHeader - the text for the header line
level - an integer between 0 and 4. The exception is logged if greater or equal the log level,

getExceptionCount

public long getExceptionCount()
Description copied from interface: ILogger
Return the number of exceptions since startup

Specified by:
getExceptionCount in interface ILogger
Returns:
a long value

getLastExceptionDate

public java.util.Date getLastExceptionDate()
Description copied from interface: ILogger
Return the date when the last exception has occured

Specified by:
getLastExceptionDate in interface ILogger
Returns:
a date value

getLogFile

public java.io.File getLogFile()
                        throws ApplicationException
Return the Reader to read the current log file. The reader should be closed by the caller after usage. Returns null when logging on console.

Specified by:
getLogFile in interface ILogger
Returns:
the log file
Throws:
ApplicationException

getErrorLogFile

public java.io.File getErrorLogFile()
                             throws ApplicationException
Description copied from interface: ILogger
The file where errors are logged, if errors are logged to a separate file.

Specified by:
getErrorLogFile in interface ILogger
Returns:
the error file
Throws:
ApplicationException

getWriter

public java.io.PrintWriter getWriter()
Return the Writer to write some stuff to the log file. Do not close this writer, it is used for logging.

Specified by:
getWriter in interface ILogger

getLevel

public int getLevel()
Returns the log level.

Specified by:
getLevel in interface ILogger

restart

public void restart()
             throws ApplicationException
Description copied from interface: ILogger
Restart the Logger (reinitialize log file)

Specified by:
restart in interface ILogger
Throws:
ApplicationException

getLogPrefix

protected java.lang.String getLogPrefix(int level)
Returns the prefix of a log entry (which is the part before the specific log message). This prefix consists of the log level, the threads name and the current date.

Parameters:
level -


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.