Class BasicTestCaptureCallLogger
CallLogger
that captures log entries for testing logging itself.
Instead of logging messages to a log file, messages are simply kept in an internal atomic string reference.
Once a message has been logged, you can use the getMessage()
or assertMessage()
methods
to access and evaluate it.
The following example shows how the capture logger can be associated with a REST class so that logged messages can be examined.
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.rest.logger.CallLogger
CallLogger.Builder, CallLogger.Void
-
Field Summary
Fields inherited from class org.apache.juneau.rest.logger.CallLogger
SP_enabled, SP_level, SP_logger, SP_requestDetail, SP_responseDetail
-
Constructor Summary
ConstructorDescriptionConstructor using default settings.BasicTestCaptureCallLogger
(BeanStore beanStore) Constructor using specific settings. -
Method Summary
Modifier and TypeMethodDescriptionReturns an assertion of the last logged message.Returns an assertion of the last logged message and then deletes it internally.Returns the last logged message level.getLevel()
Returns the last logged message level.Returns the last logged message.Returns the last logged message and then deletes it internally.Returns the last logged message level.protected CallLogger.Builder
Initializer.protected void
Logs the specified message to the logger.reset()
Resets the internal message buffer.
-
Constructor Details
-
BasicTestCaptureCallLogger
Constructor using specific settings.- Parameters:
beanStore
- The bean store containing injectable beans for this logger.
-
BasicTestCaptureCallLogger
public BasicTestCaptureCallLogger()Constructor using default settings.Uses the same settings as
CallLogger
.
-
-
Method Details
-
init
Description copied from class:CallLogger
Initializer.Subclasses should override this method to make modifications to the builder used to create this logger.
- Overrides:
init
in classCallLogger
- Parameters:
beanStore
- The bean store containing injectable beans for this logger.- Returns:
- A new builder object.
-
log
Description copied from class:CallLogger
Logs the specified message to the logger.Subclasses can override this method to capture messages being sent to the logger and handle it differently.
- Overrides:
log
in classCallLogger
- Parameters:
level
- The log level.msg
- The log message.e
- The exception.
-
getMessage
Returns the last logged message.- Returns:
- The last logged message, or
null if nothing was logged.
-
getMessageAndReset
Returns the last logged message and then deletes it internally.- Returns:
- The last logged message.
-
assertMessage
Returns an assertion of the last logged message.- Returns:
- The last logged message as an assertion object. Never
null .
-
assertMessageAndReset
Returns an assertion of the last logged message and then deletes it internally.- Returns:
- The last logged message as an assertion object. Never
null .
-
getLevel
Returns the last logged message level.- Returns:
- The last logged message level, or
null if nothing was logged.
-
getThrown
Returns the last logged message level.- Returns:
- The last logged message level, or
null if nothing was logged.
-
assertThrown
Returns the last logged message level.- Returns:
- The last logged message level, or
null if nothing was logged.
-
reset
Resets the internal message buffer.- Returns:
- This object.
-