org.sandev.tools.util
Class JavaLogger

java.lang.Object
  extended by org.sandev.tools.util.JavaLogger
All Implemented Interfaces:
org.sandev.basics.nodecommon.Logger

public class JavaLogger
extends java.lang.Object
implements org.sandev.basics.nodecommon.Logger

/** A SAND Logger implementation that wraps the standard JDK Logger as obtained from the environment.


Field Summary
protected  java.util.logging.Logger jdkLogger
          The JDK Logger we are wrapping.
protected  int logLevel
          The current SAND log level.
protected  java.lang.String sourceID
          An identifying sourceID used for log output.
 
Fields inherited from interface org.sandev.basics.nodecommon.Logger
LOGLEVEL_DEBUG, LOGLEVEL_ERROR, LOGLEVEL_FATAL, LOGLEVEL_INFO, LOGLEVEL_STR_DEBUG, LOGLEVEL_STR_ERROR, LOGLEVEL_STR_FATAL, LOGLEVEL_STR_INFO, LOGLEVEL_STR_WARN, LOGLEVEL_STRINGS, LOGLEVEL_WARN
 
Constructor Summary
JavaLogger()
          Default ctor does nothing.
 
Method Summary
 java.util.logging.Logger getJDKLogger()
          Return the JDK logger
 int getLogLevel()
          Return the log level.
 java.lang.String getSourceID()
          Return the instanceName
 void init(java.lang.String instanceName)
          Initialize our native logger using the specified instance name
 void log(int severity, java.lang.String msg)
          Implementation of the required log method.
 void setLogLevel(int logLevel)
          Set the log level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logLevel

protected int logLevel
The current SAND log level.


sourceID

protected java.lang.String sourceID
An identifying sourceID used for log output. This is set in the init method.


jdkLogger

protected java.util.logging.Logger jdkLogger
The JDK Logger we are wrapping. This is set in the init method.

Constructor Detail

JavaLogger

public JavaLogger()
Default ctor does nothing. Call the init method for setup.

Method Detail

setLogLevel

public void setLogLevel(int logLevel)
Set the log level.

Specified by:
setLogLevel in interface org.sandev.basics.nodecommon.Logger

getLogLevel

public int getLogLevel()
Return the log level.

Specified by:
getLogLevel in interface org.sandev.basics.nodecommon.Logger

getSourceID

public java.lang.String getSourceID()
Return the instanceName


getJDKLogger

public java.util.logging.Logger getJDKLogger()
Return the JDK logger


init

public void init(java.lang.String instanceName)
          throws org.sandev.basics.nodecommon.LoggerException
Initialize our native logger using the specified instance name

Specified by:
init in interface org.sandev.basics.nodecommon.Logger
Throws:
org.sandev.basics.nodecommon.LoggerException

log

public void log(int severity,
                java.lang.String msg)
         throws org.sandev.basics.nodecommon.LoggerException
Implementation of the required log method. See the Logger interface documentation for details.

SAND log levels map to JDK log levels as:

LOGLEVEL_DEBUG is mapped to info rather than fine because fine output typically requires enabling trace output in the container which is a prohibitive flood of log info. There is no differentiation between LOGLEVEL_ERROR and LOGLEVEL_FATAL in the standard java.util.logging.Level so these both map to severe.

We call the precise (logp) methods using the logger instance identifier as the class name and the SAND severity level as the method name. This is because the logger printing the full class name and best guess of the method name is unnecessarily verbose and potentially innacurate.

Note that there are two filtering mechanisms at work when the application is running:

  1. SAND log filtering
  2. Container log filtering
Squelching output on either one will limit log output.

Specified by:
log in interface org.sandev.basics.nodecommon.Logger
Throws:
org.sandev.basics.nodecommon.LoggerException