站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

Log (NB JUnit) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.nbjunit/1 1.41

org.netbeans.junit
Class Log

java.lang.Object
  extended by java.util.logging.Handler
      extended by org.netbeans.junit.Log

public final class Log
extends Handler

Collects log messages.


Constructor Summary
Log()
          Creates a new instance of Log
 
Method Summary
 void close()
           
static void controlFlow(Logger listenTo, Logger reportTo, String order, int timeout)
          Can emulate the execution flow of multiple threads in a deterministic way so it is easy to emulate race conditions or deadlocks just with the use of additional log messages inserted into the code.
static CharSequence enable(String loggerName, Level level)
          Enables logging for given logger name and given severity.
 void flush()
           
 void publish(LogRecord record)
           
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log

public Log()
Creates a new instance of Log

Method Detail

enable

public static CharSequence enable(String loggerName,
                                  Level level)
Enables logging for given logger name and given severity. Everything logged to the object is going to go to the returned CharSequence object which can be used to check the content or converted toString.

The logging stops when the returned object is garbage collected.

Parameters:
loggerName - the name to capture logging for
level - the level of details one wants to get
Returns:
character sequence which can be check or converted to string
Since:
1.27

controlFlow

public static void controlFlow(Logger listenTo,
                               Logger reportTo,
                               String order,
                               int timeout)
Can emulate the execution flow of multiple threads in a deterministic way so it is easy to emulate race conditions or deadlocks just with the use of additional log messages inserted into the code.

The best example showing usage of this method is real life test. Read FlowControlTest.java to know everything about the expected usage of this method.

The method does listen on output send to a logger listenTo by various threads and either suspends them or wake them up trying as best as it can to mimic the log output described in order. Of course, this may not always be possible, so there is the timeout value which specifies the maximum time a thread can be suspended while waiting for a single message. The information about the internal behaviour of the controlFlow method can be send to reportTo logger, if provided, so in case of failure one can analyse what went wrong.

The format of the order is a set of lines like:

 THREAD:name_of_the_thread MSG:message_to_expect
 
which define the order saying that at this time a thread with a given name is expected to send given message. Both the name of the thread and the message are regular expressions so one can shorten them by using .* or any other trick. Btw. the format of the order is similar to the one logged by the enable(java.lang.String, java.util.logging.Level) or NbTestCase.logLevel() methods, so when one gets a test failure with enabled logging, it is enough to just delete the unnecessary messages, replace too specific texts like @574904 with .* and the order is ready for use.

Parameters:
listenTo - the logger to listen to and guide the execution according to messages sent to it
reportTo - the logger to report internal state to or null if the logging is not needed
order - the string describing the expected execution order of threads
timeout - the maximal wait time of each thread on given message, zero if the waiting shall be infinite
Since:
1.28

publish

public void publish(LogRecord record)
Specified by:
publish in class Handler

flush

public void flush()
Specified by:
flush in class Handler

close

public void close()
Specified by:
close in class Handler

org.netbeans.modules.nbjunit/1 1.41

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.