public class LogTestAssist extends Object
| Constructor and Description |
|---|
LogTestAssist()
Creates a new helper which doesn't track any logger output.
|
LogTestAssist(String name)
Creates a new helper which tracks the log events sent out to
the logger with the given name.
|
LogTestAssist(String name,
org.apache.log4j.Level level)
Creates a new helper which tracks the log events sent out to
the logger with the given name at the given optional threshold
level.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
assertEvent(org.apache.log4j.spi.LoggingEvent event,
org.apache.log4j.Level level,
String logger,
String message,
String location)
Asserts that the contents of the given event match the given
expected level, logger name, message, and location.
|
void |
assertEventCount(int count)
Asserts that the receiver's collector contains the given number
of events.
|
void |
assertLastEvent(org.apache.log4j.Level level,
String logger,
String message,
String location)
Asserts that the contents of the receiver's collector's most
recent event match the given expected level, logger name,
message, and location.
|
void |
assertNoEvents()
Asserts that the receiver's collector contains no events.
|
void |
assertSingleEvent(org.apache.log4j.Level level,
String logger,
String message,
String location)
Asserts that the receiver's collector contains a single event,
and that its contents match the given expected level, logger
name, message, and location.
|
void |
assertSomeEvent(org.apache.log4j.Level level,
String logger,
String message,
String location)
Asserts that at least one of the receiver's collector's events
matches the given expected level, logger name, message, and
location.
|
MemoryAppender |
getAppender()
Returns the receiver's collector (appender) of retained events.
|
String |
getEventsAsString()
Returns a string with all the events of the receiver's
collector.
|
void |
resetAppender()
Clears the contents of the receiver's collector.
|
static void |
setDefaultLevel(org.apache.log4j.Level level)
Sets the level of the root logger to the given level.
|
static void |
setLevel(String name,
org.apache.log4j.Level level)
Sets the level of the logger with the given name to the given
level.
|
void |
trackLogger(String name)
Starts tracking log events sent out to the logger with the
given name.
|
void |
trackLogger(String name,
org.apache.log4j.Level level)
Starts tracking log events sent out to the logger with the
given name at the given optional threshold level.
|
public LogTestAssist(String name, org.apache.log4j.Level level)
name - The logger name.level - The level. It may be null, in which case logger's
threshold level is not altered.public LogTestAssist(String name)
name - The logger name.public LogTestAssist()
trackLogger(String,org.apache.log4j.Level).public static void setDefaultLevel(org.apache.log4j.Level level)
level - The level.public static void setLevel(String name, org.apache.log4j.Level level)
name - The logger name.level - The level.public static void assertEvent(org.apache.log4j.spi.LoggingEvent event,
org.apache.log4j.Level level,
String logger,
String message,
String location)
event - The event.level - The expected level. Use null to indicate "don't
care".logger - The expected logger name. Use null to indicate
"don't care".message - The expected message. Use null to indicate
"don't care".location - The expected location. Use null to indicate
"don't care".public void trackLogger(String name, org.apache.log4j.Level level)
name - The logger name.level - The level. It may be null, in which case logger's
threshold level is not altered.public void trackLogger(String name)
name - The logger name.public void resetAppender()
public String getEventsAsString()
public MemoryAppender getAppender()
public void assertEventCount(int count)
count - The number of events.public void assertNoEvents()
public void assertLastEvent(org.apache.log4j.Level level,
String logger,
String message,
String location)
level - The expected level. Use null to indicate "don't
care".logger - The expected logger name. Use null to indicate
"don't care".message - The expected message. Use null to indicate
"don't care".location - The expected location. Use null to indicate
"don't care".public void assertSomeEvent(org.apache.log4j.Level level,
String logger,
String message,
String location)
level - The expected level. Use null to indicate "don't
care".logger - The expected logger name. Use null to indicate
"don't care".message - The expected message. Use null to indicate
"don't care".location - The expected location. Use null to indicate
"don't care".public void assertSingleEvent(org.apache.log4j.Level level,
String logger,
String message,
String location)
level - The expected level. Use null to indicate "don't
care".logger - The expected logger name. Use null to indicate
"don't care".message - The expected message. Use null to indicate
"don't care".location - The expected location. Use null to indicate
"don't care".Copyright © 2014. All Rights Reserved.