SmartFrog 3.10.000

org.smartfrog.sfcore.logging
Class LogToStreamsImpl

java.lang.Object
  extended by org.smartfrog.sfcore.logging.LogToNothingImpl
      extended by org.smartfrog.sfcore.logging.LogToStreamsImpl
All Implemented Interfaces:
Log, LogLevel, LogMessage, LogToNothing, LogToStreams
Direct Known Subclasses:
LogToFileImpl, LogToPrimImpl

public class LogToStreamsImpl
extends LogToNothingImpl
implements LogToStreams, Log, LogMessage, LogLevel

Simple implementation of Log that sends all enabled log messages, for all defined loggers, to System.out. The following system properties are supported to configure the behavior of this logger:


Field Summary
protected  int callDepth
          Depth in StackTrace it will depend on how this Log is used and connected to LogImpl
protected  int currentLogLevel
          The current log level
protected  java.text.DateFormat dateFormatter
          Used to format times
protected static java.lang.String[] ERROR_NAMES
          text for error levels
protected  java.lang.String logName
          The name of this simple log instance
protected  boolean showDateTime
          Include the current time in the log message
protected  boolean showLogName
          Include the instance name in the log message?
protected  boolean showMethodCall
          Include package name in the log message
protected  boolean showShortName
          Include the short name ( last component ) of the logger in the log message.
protected  boolean showStackTrace
          Include stack trace in the log message
protected  boolean showThreadName
          Include thread name in the log message
 
Fields inherited from class org.smartfrog.sfcore.logging.LogToNothingImpl
classComponentDescription, componentComponentDescription, errstream, errToOut, outstream
 
Fields inherited from interface org.smartfrog.sfcore.logging.LogToStreams
ATR_DATE_FORMAT, ATR_SHOW_DATE_TIME, ATR_SHOW_LOG_NAME, ATR_SHOW_METHOD_CALL, ATR_SHOW_SHORT_NAME, ATR_SHOW_STACK_TRACE, ATR_SHOW_THREAD_NAME
 
Fields inherited from interface org.smartfrog.sfcore.logging.LogToNothing
ATR_ERR_TO_OUT
 
Fields inherited from interface org.smartfrog.sfcore.logging.LogLevel
LOG_LEVEL_ALL, LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_FATAL, LOG_LEVEL_IGNORE, LOG_LEVEL_INFO, LOG_LEVEL_OFF, LOG_LEVEL_TRACE, LOG_LEVEL_WARN
 
Constructor Summary
protected LogToStreamsImpl()
          Construct a simple log with given name and log level and log to output level
  LogToStreamsImpl(java.lang.String name, ComponentDescription componentComponentDescription, java.lang.Integer initialLogLevel)
          Construct a simple log with given name and log level and log to output level
  LogToStreamsImpl(java.lang.String name, ComponentDescription componentComponentDescription, java.lang.Integer initialLogLevel, java.io.PrintStream out, java.io.PrintStream err)
          Construct a simple log with given name and log level and log to output level
  LogToStreamsImpl(java.lang.String name, java.lang.Integer initialLogLevel)
          Construct a simple log with given name and log level and log to output level
  LogToStreamsImpl(java.lang.String name, java.lang.Integer initialLogLevel, java.io.PrintStream out, java.io.PrintStream err)
          Construct a simple log with given name and log level and log to output level
 
Method Summary
 void debug(java.lang.Object message)
           Log a message with debug log level.
 void debug(java.lang.Object message, java.lang.Throwable t)
           Log an error with debug log level.
 void error(java.lang.Object message)
           Log a message with error log level.
 void error(java.lang.Object message, java.lang.Throwable t)
           Log an error with error log level.
 void fatal(java.lang.Object message)
           Log a message with fatal log level.
 void fatal(java.lang.Object message, java.lang.Throwable t)
           Log an error with fatal log level.
 int getLevel()
           Get logging level.
 void info(java.lang.Object message)
           Log a message with info log level.
 void info(java.lang.Object message, java.lang.Throwable t)
           Log an error with info log level.
 boolean isDebugEnabled()
           Are debug messages currently enabled?
 boolean isErrorEnabled()
           Are error messages currently enabled?
 boolean isFatalEnabled()
           Are fatal messages currently enabled?
 boolean isInfoEnabled()
           Are info messages currently enabled?
 boolean isLevelEnabled(int logLevel)
          Is the given log level currently enabled?
 boolean isTraceEnabled()
           Are trace messages currently enabled?
 boolean isWarnEnabled()
           Are warn messages currently enabled?
protected  void log(int type, java.lang.Object message, java.lang.Throwable t)
           Do the actual logging.
protected  java.lang.StringBuffer logToText(int type, java.lang.Object message, java.lang.Throwable t)
          Do the logging.
protected  void readSFStreamsAttributes(ComponentDescription cd)
          Reads optional and mandatory attributes.
 void setErrstream(java.io.PrintStream errstream)
          set the output stream for logging.
 void setLevel(int currentLogLevel)
           Set logging level.
 void setOutstream(java.io.PrintStream outstream)
          set the output stream for logging.
 void trace(java.lang.Object message)
           Log a message with trace log level.
 void trace(java.lang.Object message, java.lang.Throwable t)
           Log an error with trace log level.
 void warn(java.lang.Object message)
           Log a message with warn log level.
 void warn(java.lang.Object message, java.lang.Throwable t)
           Log an error with warn log level.
protected  void write(java.lang.StringBuffer buffer)
          Write the content of the message accumulated in the specified StringBuffer to the appropriate output destination.
 
Methods inherited from class org.smartfrog.sfcore.logging.LogToNothingImpl
err, err, err, err, out, readSFNothingAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.smartfrog.sfcore.logging.LogMessage
err, err, err, err, out
 

Field Detail

showLogName

protected boolean showLogName
Include the instance name in the log message?


showShortName

protected boolean showShortName
Include the short name ( last component ) of the logger in the log message. Default to true - otherwise we'll be lost in a flood of messages without knowing who sends them.


showDateTime

protected boolean showDateTime
Include the current time in the log message


showThreadName

protected boolean showThreadName
Include thread name in the log message


showMethodCall

protected boolean showMethodCall
Include package name in the log message


showStackTrace

protected boolean showStackTrace
Include stack trace in the log message


dateFormatter

protected java.text.DateFormat dateFormatter
Used to format times


logName

protected java.lang.String logName
The name of this simple log instance


currentLogLevel

protected int currentLogLevel
The current log level


callDepth

protected int callDepth
Depth in StackTrace it will depend on how this Log is used and connected to LogImpl


ERROR_NAMES

protected static final java.lang.String[] ERROR_NAMES
text for error levels

Constructor Detail

LogToStreamsImpl

protected LogToStreamsImpl()
Construct a simple log with given name and log level and log to output level


LogToStreamsImpl

public LogToStreamsImpl(java.lang.String name,
                        java.lang.Integer initialLogLevel)
Construct a simple log with given name and log level and log to output level

Parameters:
name - log name
initialLogLevel - level to log at

LogToStreamsImpl

public LogToStreamsImpl(java.lang.String name,
                        ComponentDescription componentComponentDescription,
                        java.lang.Integer initialLogLevel)
Construct a simple log with given name and log level and log to output level

Parameters:
name - log name
componentComponentDescription - A component description to overwrite class configuration
initialLogLevel - level to log at

LogToStreamsImpl

public LogToStreamsImpl(java.lang.String name,
                        java.lang.Integer initialLogLevel,
                        java.io.PrintStream out,
                        java.io.PrintStream err)
Construct a simple log with given name and log level and log to output level

Parameters:
name - log name
initialLogLevel - level to log at
out - output stream to log to
err - error stream to log to

LogToStreamsImpl

public LogToStreamsImpl(java.lang.String name,
                        ComponentDescription componentComponentDescription,
                        java.lang.Integer initialLogLevel,
                        java.io.PrintStream out,
                        java.io.PrintStream err)
Construct a simple log with given name and log level and log to output level

Parameters:
name - log name
componentComponentDescription - A component description to overwrite class configuration
initialLogLevel - level to log at
out - output stream to log to
err - error stream to log to
Method Detail

readSFStreamsAttributes

protected void readSFStreamsAttributes(ComponentDescription cd)
                                throws SmartFrogException
Reads optional and mandatory attributes.

Parameters:
cd - cd ComponentDescription A component description to read attributes from
Throws:
SmartFrogException - error while reading attributes

setOutstream

public void setOutstream(java.io.PrintStream outstream)
set the output stream for logging. must not be null

Overrides:
setOutstream in class LogToNothingImpl
Parameters:
outstream - output stream to log to

setErrstream

public void setErrstream(java.io.PrintStream errstream)
set the output stream for logging. must not be null

Overrides:
setErrstream in class LogToNothingImpl
Parameters:
errstream - error stream to log to

setLevel

public void setLevel(int currentLogLevel)

Set logging level.

Specified by:
setLevel in interface LogLevel
Overrides:
setLevel in class LogToNothingImpl
Parameters:
currentLogLevel - new logging level

getLevel

public int getLevel()

Get logging level.

Specified by:
getLevel in interface LogLevel
Overrides:
getLevel in class LogToNothingImpl
Returns:
int log level

log

protected void log(int type,
                   java.lang.Object message,
                   java.lang.Throwable t)

Do the actual logging. This method assembles the message and then calls write() to cause it to be written.

Parameters:
type - One of the LOG_LEVE_XXX constants defining the log level
message - The message itself (typically a String)
t - The exception whose stack trace should be logged

logToText

protected java.lang.StringBuffer logToText(int type,
                                           java.lang.Object message,
                                           java.lang.Throwable t)

Do the logging. Uses String buffer to assemble the message.

Parameters:
type - One of the LOG_LEVE_XXX constants defining the log level
message - The message itself (typically a String)
t - The exception whose stack trace should be logged
Returns:
StringBuffer

write

protected void write(java.lang.StringBuffer buffer)

Write the content of the message accumulated in the specified StringBuffer to the appropriate output destination.

this is the output stream specified in the constructor or, by default, the reference to System.out at the time of construction. Changes to System.out are not picked up.

Parameters:
buffer - A StringBuffer containing the accumulated text to be logged

isLevelEnabled

public boolean isLevelEnabled(int logLevel)
Is the given log level currently enabled?

Specified by:
isLevelEnabled in interface LogLevel
Overrides:
isLevelEnabled in class LogToNothingImpl
Parameters:
logLevel - is this level enabled?
Returns:
boolean true if given log level is currently enabled

debug

public void debug(java.lang.Object message)

Log a message with debug log level.

Specified by:
debug in interface Log
Overrides:
debug in class LogToNothingImpl
Parameters:
message - log this message

debug

public void debug(java.lang.Object message,
                  java.lang.Throwable t)

Log an error with debug log level.

Specified by:
debug in interface Log
Overrides:
debug in class LogToNothingImpl
Parameters:
message - log this message
t - log this cause

trace

public void trace(java.lang.Object message)

Log a message with trace log level.

Specified by:
trace in interface Log
Overrides:
trace in class LogToNothingImpl
Parameters:
message - log this message

trace

public void trace(java.lang.Object message,
                  java.lang.Throwable t)

Log an error with trace log level.

Specified by:
trace in interface Log
Overrides:
trace in class LogToNothingImpl
Parameters:
message - log this message
t - log this cause

info

public void info(java.lang.Object message)

Log a message with info log level.

Specified by:
info in interface Log
Overrides:
info in class LogToNothingImpl
Parameters:
message - log this message

info

public void info(java.lang.Object message,
                 java.lang.Throwable t)

Log an error with info log level.

Specified by:
info in interface Log
Overrides:
info in class LogToNothingImpl
Parameters:
message - log this message
t - log this cause

warn

public void warn(java.lang.Object message)

Log a message with warn log level.

Specified by:
warn in interface Log
Overrides:
warn in class LogToNothingImpl
Parameters:
message - log this message

warn

public void warn(java.lang.Object message,
                 java.lang.Throwable t)

Log an error with warn log level.

Specified by:
warn in interface Log
Overrides:
warn in class LogToNothingImpl
Parameters:
message - log this message
t - log this cause

error

public void error(java.lang.Object message)

Log a message with error log level.

Specified by:
error in interface Log
Overrides:
error in class LogToNothingImpl
Parameters:
message - log this message

error

public void error(java.lang.Object message,
                  java.lang.Throwable t)

Log an error with error log level.

Specified by:
error in interface Log
Overrides:
error in class LogToNothingImpl
Parameters:
message - log this message
t - log this cause

fatal

public void fatal(java.lang.Object message)

Log a message with fatal log level.

Specified by:
fatal in interface Log
Overrides:
fatal in class LogToNothingImpl
Parameters:
message - log this message

fatal

public void fatal(java.lang.Object message,
                  java.lang.Throwable t)

Log an error with fatal log level.

Specified by:
fatal in interface Log
Overrides:
fatal in class LogToNothingImpl
Parameters:
message - log this message
t - log this cause

isDebugEnabled

public boolean isDebugEnabled()

Are debug messages currently enabled?

This allows expensive operations such as String concatenation to be avoided when the message will be ignored by the logger.

Specified by:
isDebugEnabled in interface Log
Overrides:
isDebugEnabled in class LogToNothingImpl
Returns:
boolean true if debug level is currently enabled

isErrorEnabled

public boolean isErrorEnabled()

Are error messages currently enabled?

This allows expensive operations such as String concatenation to be avoided when the message will be ignored by the logger.

Specified by:
isErrorEnabled in interface Log
Overrides:
isErrorEnabled in class LogToNothingImpl
Returns:
boolean true if error level is currently enabled

isFatalEnabled

public boolean isFatalEnabled()

Are fatal messages currently enabled?

This allows expensive operations such as String concatenation to be avoided when the message will be ignored by the logger.

Specified by:
isFatalEnabled in interface Log
Overrides:
isFatalEnabled in class LogToNothingImpl
Returns:
boolean true if fatal level is currently enabled

isInfoEnabled

public boolean isInfoEnabled()

Are info messages currently enabled?

This allows expensive operations such as String concatenation to be avoided when the message will be ignored by the logger.

Specified by:
isInfoEnabled in interface Log
Overrides:
isInfoEnabled in class LogToNothingImpl
Returns:
boolean true if info level is currently enabled

isTraceEnabled

public boolean isTraceEnabled()

Are trace messages currently enabled?

This allows expensive operations such as String concatenation to be avoided when the message will be ignored by the logger.

Specified by:
isTraceEnabled in interface Log
Overrides:
isTraceEnabled in class LogToNothingImpl
Returns:
boolean true if trace level is currently enabled

isWarnEnabled

public boolean isWarnEnabled()

Are warn messages currently enabled?

This allows expensive operations such as String concatenation to be avoided when the message will be ignored by the logger.

Specified by:
isWarnEnabled in interface Log
Overrides:
isWarnEnabled in class LogToNothingImpl
Returns:
boolean true if warn level is currently enabled

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP