| java.lang.Object java.util.logging.Handler org.netbeans.junit.Log
Log | final public class Log extends Handler (Code) | | Collects log messages.
author: Jaroslav Tulach |
Constructor Summary | |
public | Log() |
Method Summary | |
public static void | assertInstances(String msg) Assert to verify that all collected instances via
enableInstances
can disappear. | public void | close() | static void | configure(Level lev, NbTestCase current) | 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. | public static CharSequence | enable(String loggerName, Level level) Enables logging for given logger name and given severity. | public static void | enableInstances(Logger log, String msg, Level level) Starts to listen on given log and collect parameters of messages that
were send to it. | public void | flush() | public void | publish(LogRecord record) | static Throwable | wrapWithMessages(Throwable ex) |
Log | public Log()(Code) | | Creates a new instance of Log
|
assertInstances | public static void assertInstances(String msg)(Code) | | Assert to verify that all collected instances via
enableInstances
can disappear. Uses
NbTestCase.assertGC on each of them.
Parameters: msg - message to display in case of potential failure |
close | public void close()(Code) | | |
controlFlow | public static void controlFlow(Logger listenTo, Logger reportTo, String order, int timeout)(Code) | | 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
Log.enable 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 Parameters: reportTo - the logger to report internal state to or null if the logging is not needed Parameters: order - the string describing the expected execution order of threads Parameters: timeout - the maximal wait time of each thread on given message, zero if the waiting shall be infinite author: Jaroslav Tulach, invented during year 2005 since: 1.28 |
enable | public static CharSequence enable(String loggerName, Level level)(Code) | | 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 Parameters: level - the level of details one wants to get character sequence which can be check or converted to string since: 1.27 |
enableInstances | public static void enableInstances(Logger log, String msg, Level level)(Code) | | Starts to listen on given log and collect parameters of messages that
were send to it. This is supposed to be called at the begining of a test,
to get messages from the programs that use
timers/counters
infrastructure. At the end one should call
assertInstances .
Parameters: log - logger to listen on, if null, it uses the standard timers/counters one Parameters: msg - name of messages to collect, if null, all messages will be recorded Parameters: level - level of messages to record since: 1.44 |
flush | public void flush()(Code) | | |
|
|