org.ws4d.java.util
Class Log

java.lang.Object
  extended by org.ws4d.java.util.Log

public final class Log
extends java.lang.Object

Debug class provides logging mechanism and control over the output messages.
Use this instead of System.out.println().

To change the debug level and the message output, use setDebugLevel(int level).

e.g.
setDebugLevel(Debug.DEBUG_LEVEL_WARNING);

DEBUG_LEVEL_DEBUG = highest output level, every message shown.
DEBUG_LEVEL_INFO = show information, log, warn and error messages only.
DEBUG_LEVEL_LOG = show log, warn and error messages only.
DEBUG_LEVEL_WARN = show warn and error messages only.
DEBUG_LEVEL_ERROR = show error messages only.
DEBUG_LEVEL_NO_LOGGING = show nothing.


Field Summary
static int DEBUG_LAYER_ALL
          Should be used to show all debug messages.
static int DEBUG_LAYER_APPLICATION
          Should be used to show application layer (device+service) debug messages
static int DEBUG_LAYER_COMMUNICATION
          Should be used to show communication layer (DPWS) debug messages.
static int DEBUG_LAYER_FRAMEWORK
          Should be used to show general framework debug messages.
static int DEBUG_LEVEL_DEBUG
          Sets highest output level, every message shown.
static int DEBUG_LEVEL_ERROR
          Sets level to show error messages only.
static int DEBUG_LEVEL_INFO
          Sets level to show information, warn and error messages only.
static int DEBUG_LEVEL_NO_LOGGING
          Sets level to show error messages only.
static int DEBUG_LEVEL_WARN
          Sets level to show warn and error messages only.
 
Constructor Summary
Log()
           
 
Method Summary
static void debug(java.lang.String msg)
          Logs a debug message.
static void debug(java.lang.String msg, int layer)
          Logs a debug message.
static void error(java.lang.String msg)
          Logs an error message.
static int getLogLevel()
          Gets the internal debug level for this logger.
static java.lang.String[] getStackTrace(java.lang.Throwable t)
          Returns the Java VM stack trace if possible.
static void info(java.lang.String msg)
          Logs an info message.
static boolean isDebug()
          Checks whether the current log level is at least DEBUG_LEVEL_DEBUG.
static boolean isError()
          Checks whether the current log level is at least DEBUG_LEVEL_ERROR.
static boolean isInfo()
          Checks whether the current log level is at least DEBUG_LEVEL_INFO.
static boolean isWarn()
          Checks whether the current log level is at least DEBUG_LEVEL_WARN.
static void printStackTrace(java.lang.Throwable t)
          Prints stack trace, if debug level is "Error" or higher and logging of stack traces is on.
static void setErrorOutput(java.io.OutputStream newout)
           
static void setLogLevel(int level)
          Sets the internal debug level for this logger.
static void setLogLevel(int level, int layers)
          Sets the internal debug level for this logger.
static void setLogStackTrace(boolean logStackTrace)
          Sets logging of stack traces on or off.
static void setNormalOutput(java.io.OutputStream newout)
           
static void setShowTimestamp(boolean set)
          Sets time stamp on or off.
static void subscribe(LogSubscriber ds)
          Subscribes to notification list for receiving debug messages.
static void unsubscribe(LogSubscriber ds)
          Unsubscribes from notification list.
static void warn(java.lang.String msg)
          Logs a warning message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_LAYER_ALL

public static final int DEBUG_LAYER_ALL
Should be used to show all debug messages.

See Also:
Constant Field Values

DEBUG_LAYER_FRAMEWORK

public static final int DEBUG_LAYER_FRAMEWORK
Should be used to show general framework debug messages.

See Also:
Constant Field Values

DEBUG_LAYER_APPLICATION

public static final int DEBUG_LAYER_APPLICATION
Should be used to show application layer (device+service) debug messages

See Also:
Constant Field Values

DEBUG_LAYER_COMMUNICATION

public static final int DEBUG_LAYER_COMMUNICATION
Should be used to show communication layer (DPWS) debug messages.

See Also:
Constant Field Values

DEBUG_LEVEL_DEBUG

public static final int DEBUG_LEVEL_DEBUG
Sets highest output level, every message shown.

See Also:
Constant Field Values

DEBUG_LEVEL_INFO

public static final int DEBUG_LEVEL_INFO
Sets level to show information, warn and error messages only.

See Also:
Constant Field Values

DEBUG_LEVEL_WARN

public static final int DEBUG_LEVEL_WARN
Sets level to show warn and error messages only.

See Also:
Constant Field Values

DEBUG_LEVEL_ERROR

public static final int DEBUG_LEVEL_ERROR
Sets level to show error messages only.

See Also:
Constant Field Values

DEBUG_LEVEL_NO_LOGGING

public static final int DEBUG_LEVEL_NO_LOGGING
Sets level to show error messages only.

See Also:
Constant Field Values
Constructor Detail

Log

public Log()
Method Detail

setShowTimestamp

public static void setShowTimestamp(boolean set)
Sets time stamp on or off.

Parameters:
set - true if Debug should show time stamps, false if not.

setLogStackTrace

public static void setLogStackTrace(boolean logStackTrace)
Sets logging of stack traces on or off.

Parameters:
logStackTrace - true if Debug should log stack traces, false if not.

setLogLevel

public static void setLogLevel(int level)
Sets the internal debug level for this logger.

Parameters:
level - the debug level to set.

setLogLevel

public static void setLogLevel(int level,
                               int layers)
Sets the internal debug level for this logger.

The set layers could be a single layer or a combination of them

Parameters:
level - the debug level to set.
layers - the layers which debug messages should be shown for.
See Also:
DEBUG_LAYER_ALL, DEBUG_LAYER_APPLICATION, DEBUG_LAYER_COMMUNICATION, DEBUG_LAYER_FRAMEWORK

getLogLevel

public static int getLogLevel()
Gets the internal debug level for this logger.

Returns:
the debug level.

isDebug

public static boolean isDebug()
Checks whether the current log level is at least DEBUG_LEVEL_DEBUG.

Returns:
whether the current log level is at least DEBUG_LEVEL_DEBUG or not

isInfo

public static boolean isInfo()
Checks whether the current log level is at least DEBUG_LEVEL_INFO.

Returns:
whether the current log level is at least DEBUG_LEVEL_INFO or not

isWarn

public static boolean isWarn()
Checks whether the current log level is at least DEBUG_LEVEL_WARN.

Returns:
whether the current log level is at least DEBUG_LEVEL_WARN or not

isError

public static boolean isError()
Checks whether the current log level is at least DEBUG_LEVEL_ERROR.

Returns:
whether the current log level is at least DEBUG_LEVEL_ERROR or not

debug

public static void debug(java.lang.String msg)
Logs a debug message.
Use this for debugging messages.
The message is logged only when the current debug level is >= DEBUG_LEVEL_DEBUG.

Parameters:
msg - the message to log.

debug

public static void debug(java.lang.String msg,
                         int layer)
Logs a debug message.
Use this for debugging messages.
The message is logged only when the current debug level is >= DEBUG_LEVEL_DEBUG.

Parameters:
msg - the message to log.

info

public static void info(java.lang.String msg)
Logs an info message.
Use this for informational messages.
The message is logged only when the current debug level is >= DEBUG_LEVEL_INFO.

Parameters:
msg - the message to log.

error

public static void error(java.lang.String msg)
Logs an error message.
Use this for messages regarding critical errors.
The message is logged only when the current debug level is >= DEBUG_LEVEL_ERROR.

Parameters:
msg - the message to log.

warn

public static void warn(java.lang.String msg)
Logs a warning message.
Use this for messages about malfunctions which are not so severe to be treated as errors.
The message is logged only when the current debug level is >= DEBUG_LEVEL_WARN.

Parameters:
msg - the message to log.

printStackTrace

public static void printStackTrace(java.lang.Throwable t)
Prints stack trace, if debug level is "Error" or higher and logging of stack traces is on. Will be printed to error output if possible. Within CLDC environment log will be printed to System.err.

Parameters:
t - the throwable.

getStackTrace

public static java.lang.String[] getStackTrace(java.lang.Throwable t)
Returns the Java VM stack trace if possible.

Can return null if the platform does not support access to the stack trace!

Parameters:
t - stack trace
Returns:
stack trace as array of String.

subscribe

public static void subscribe(LogSubscriber ds)
Subscribes to notification list for receiving debug messages. This is especially useful when you want to stay informed about new debug messages on devices without a console output (like CLDC/MIDP devices).

Parameters:
ds - an object wants to subscribe for debug messages.
See Also:
LogSubscriber

unsubscribe

public static void unsubscribe(LogSubscriber ds)
Unsubscribes from notification list.

Parameters:
ds - an object wants to unsubscribe form debug messages
See Also:
LogSubscriber

setNormalOutput

public static void setNormalOutput(java.io.OutputStream newout)

setErrorOutput

public static void setErrorOutput(java.io.OutputStream newout)