com.groiss.log
Class Logger

java.lang.Object
  extended by com.groiss.log.Logger
All Implemented Interfaces:
Lifecycle, 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  java.lang.String errname
           
protected static long errs
           
protected  int keeperrs
           
protected  int keeplogs
           
protected static java.lang.String linesep
           
protected static java.io.PrintWriter log
           
protected static java.io.File logfile
           
protected  java.lang.String logname
           
protected  boolean logOnConsole
           
protected  long nextday
           
protected  java.io.PrintStream origout
           
protected  boolean restartdaily
           
protected  boolean restarterrdaily
           
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()
          Ask the object if it has been started
 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()
          Reconfigure gives the service the chance to react on configuration changes.
 void restart()
          Restart the Logger (reinitialize log file)
 void shutdown()
          This method is called on shutdown.
 void startup()
          This method is called when the object is "started".
 
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

logOnConsole

protected boolean logOnConsole

logname

protected java.lang.String logname

errname

protected java.lang.String errname

keeplogs

protected int keeplogs

keeperrs

protected int keeperrs

nextday

protected long nextday

restartdaily

protected boolean restartdaily

restarterrdaily

protected boolean restarterrdaily

origout

protected java.io.PrintStream origout
Constructor Detail

Logger

public Logger()

Logger

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

shutdown

public void shutdown()
Description copied from interface: Lifecycle
This method is called on shutdown.

Specified by:
shutdown in interface Lifecycle

isRunning

public boolean isRunning()
Description copied from interface: Service
Ask the object if it has been started

Specified by:
isRunning in interface Service
Returns:
true if running.

reconfigure

public void reconfigure()
Description copied from interface: Service
Reconfigure gives the service the chance to react on configuration changes. Whenever the configuration is changed the ServiceManager calls this method for all managed services.

Specified by:
reconfigure in interface Service

startup

public void startup()
Description copied from interface: Lifecycle
This method is called when the object is "started".

Specified by:
startup in interface Lifecycle

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()
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

getErrorLogFile

public java.io.File getErrorLogFile()
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

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()
Description copied from interface: ILogger
Restart the Logger (reinitialize log file)

Specified by:
restart in interface ILogger

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 -


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.