net.sf.wraplog
Class AbstractLogger

java.lang.Object
  extended bynet.sf.wraplog.AbstractLogger
Direct Known Subclasses:
Log4jLogger, NoneLogger, SunLogger, SystemLogger, WriterLogger

public abstract class AbstractLogger
extends Object

Abstract base class to write messages about interesting things happening to a log.

Author:
Thomas Aglassinger

Constructor Summary
AbstractLogger()
           
 
Method Summary
protected  void checkLevel(int logLevel, String name)
          Check that logLevel is a valid value for variable name.
 void debug(String message)
          Log a debug message.
 void debug(String format, Object item)
          Log a template based debug message, where the first {} is be replaced by a string reprenentation of item.
 void debug(String format, Object firstItem, Object secondItem)
          Log a template based debug message, where the first {} is be replaced by a string reprenentation of firstItem and the second one by secondItem.
 void debug(String message, Throwable error)
          Log a debug message with a related stack trace.
 void error(String message)
           
 void error(String format, Object item)
           
 void error(String format, Object firstItem, Object secondItem)
           
 void error(String message, Throwable error)
           
 int getLevel()
           
 int getLoggedMessageCount()
          Count of how many messages have been logged.
protected  void handleError(String message)
          Handle an error described by message.
protected  void handleError(String message, Throwable error, String originalMessage, Throwable originalError)
          Handle an error described by message caused by error while logging originalMessage and originalError.
 void info(String message)
           
 void info(String format, Object item)
           
 void info(String format, Object firstItem, Object secondItem)
           
 void info(String message, Throwable error)
           
 boolean isDebugEnabled()
           
 boolean isEnabled(int logLevel)
           
 boolean isErrorEnabled()
           
 boolean isInfoEnabled()
           
 boolean isWarnEnabled()
           
 void log(int logLevel, String message)
          Provided that getLevel() accepts it, log message.
 void log(int logLevel, String format, Object item)
           
 void log(int logLevel, String format, Object firstItem, Object secondItem)
           
 void log(int logLevel, String message, Throwable error)
          Provided that getLevel() accepts it, log message and error.
protected abstract  void reallyLog(int logLevel, String message, Throwable error)
          Log a message and optional error details.
 void setLevel(int newLevel)
           
static void setLoggingErrorHandler(LoggingErrorHandler newErrorHandler)
          Set the handler to be called when a message cannot be logged.
 void warn(String message)
           
 void warn(String format, Object item)
           
 void warn(String format, Object firstItem, Object secondItem)
           
 void warn(String message, Throwable error)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLogger

public AbstractLogger()
Method Detail

checkLevel

protected void checkLevel(int logLevel,
                          String name)
Check that logLevel is a valid value for variable name. If not, call handleError().

Parameters:
logLevel - the level to validate
name - the name of the variable that contains the value or null
See Also:
handleError(String, Throwable, String, Throwable)

debug

public void debug(String message)
Log a debug message.


debug

public void debug(String format,
                  Object item)
Log a template based debug message, where the first {} is be replaced by a string reprenentation of item.

Since:
1.2

debug

public void debug(String format,
                  Object firstItem,
                  Object secondItem)
Log a template based debug message, where the first {} is be replaced by a string reprenentation of firstItem and the second one by secondItem.

Since:
1.2

debug

public void debug(String message,
                  Throwable error)
Log a debug message with a related stack trace.


error

public void error(String message)

error

public void error(String format,
                  Object item)

error

public void error(String format,
                  Object firstItem,
                  Object secondItem)

error

public void error(String message,
                  Throwable error)

handleError

protected void handleError(String message)
Handle an error described by message.

Since:
1.2

handleError

protected void handleError(String message,
                           Throwable error,
                           String originalMessage,
                           Throwable originalError)
Handle an error described by message caused by error while logging originalMessage and originalError.

Parameters:
message - the message describing the error that prevents originalMessage from being logged
error - null or the error that prevents originalMessage from being logged
originalMessage - null the message that cannot be logged
originalError - null or the error that cannot be logged
Since:
1.3

log

public void log(int logLevel,
                String format,
                Object item)

log

public void log(int logLevel,
                String format,
                Object firstItem,
                Object secondItem)

getLevel

public int getLevel()

getLoggedMessageCount

public int getLoggedMessageCount()
Count of how many messages have been logged.


info

public void info(String message)

info

public void info(String message,
                 Throwable error)

info

public void info(String format,
                 Object item)

info

public void info(String format,
                 Object firstItem,
                 Object secondItem)

isEnabled

public boolean isEnabled(int logLevel)

reallyLog

protected abstract void reallyLog(int logLevel,
                                  String message,
                                  Throwable error)
                           throws Exception
Log a message and optional error details.

Parameters:
logLevel - one of: Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR
message - the actual message; this will never be null
error - an error that is related to the message; unless null, the name and stack trace of the error are logged
Throws:
Exception

log

public void log(int logLevel,
                String message)
Provided that getLevel() accepts it, log message. Otherwise, do nothing.


log

public void log(int logLevel,
                String message,
                Throwable error)
Provided that getLevel() accepts it, log message and error. Otherwise, do nothing.


setLevel

public void setLevel(int newLevel)

setLoggingErrorHandler

public static void setLoggingErrorHandler(LoggingErrorHandler newErrorHandler)
Set the handler to be called when a message cannot be logged.

Since:
1.3
See Also:
LoggingException

isDebugEnabled

public boolean isDebugEnabled()

isInfoEnabled

public boolean isInfoEnabled()

isWarnEnabled

public boolean isWarnEnabled()

isErrorEnabled

public boolean isErrorEnabled()

warn

public void warn(String message)

warn

public void warn(String format,
                 Object item)

warn

public void warn(String format,
                 Object firstItem,
                 Object secondItem)

warn

public void warn(String message,
                 Throwable error)