public interface MessageRecorder
A typical usage might be:
void process(MessageRecorder msgRecorder) {
msgRecorder.pushContextName(getName());
try {
// prcess task
....
// need to generate warning message
String msg = ...
msgRecorder.reportWarning(msg);
....
} finally {
msgRecorder.popContextName();
}
}
Implementations must provide the means for extracting the error/warning messages.
Code that is processing should not catch the MessageRecorder.RTException. This Exception is thrown by the MessageRecorder when too many errors have been seen. Throwing this Exception is the mechanism used to stop processing and return to the initiating code. The initiating code should expect to catch the MessageRecorder.RTException Exception.
void initiatingCode(MessageRecorder msgRecorder) {
// get MessageRecorder implementation
MessageRecorder msgRecorder = ....
try {
processingCode(msgRecorder);
} catch (MessageRecorder.RTException mrex) {
// empty
}
if (msgRecorder.hasErrors()) {
// handle errors
} else if (msgRecorder.hasWarnings()) {
// handle warnings
}
}
The reporting methods all have variations that take an "info" Object. This can be used to pass something, beyond a text message, from the point of warning/error to the initiating code.
Concerning logging, it is a rule that a message, if logged by the code creating the MessageRecorder implementation, is logged at is reporting level, errors are logged at the error log level, warnings at the warning level and info at the info level. This allows the client code to "know" what log level their messages might appear at.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear all context, warnings and errors from the MessageRecorder.
|
String |
getContext()
Get the current context string.
|
long |
getRunTimeMillis()
How long the MessageRecorder has been running since it was created or the
last time clear was called.
|
long |
getStartTimeMillis()
Get the time when the MessageRecorder was created or the last time that
the clear method was called.
|
boolean |
hasErrors()
Returns true if there are one or more error messages.
|
boolean |
hasInformation()
Returns true if there are one or more informational messages.
|
boolean |
hasWarnings()
Returns true if there are one or more warning messages.
|
void |
popContextName()
Remove the last context name added.
|
void |
pushContextName(String name)
Add the name parameter to the current context.
|
void |
reportError(Exception ex)
Add an Exception.
|
void |
reportError(Exception ex,
Object info)
Add an Exception and extra informaton.
|
void |
reportError(String msg)
Add an error message.
|
void |
reportError(String msg,
Object info)
Add an error message and extra information.
|
void |
reportInfo(String msg)
Add an informational message.
|
void |
reportInfo(String msg,
Object info)
Add an informational message and extra information.
|
void |
reportWarning(String msg)
Add a warning message.
|
void |
reportWarning(String msg,
Object info)
Add a warning message and extra information.
|
void |
throwRTException()
This simply throws a RTException.
|
void clear()
long getStartTimeMillis()
long getRunTimeMillis()
boolean hasInformation()
boolean hasWarnings()
boolean hasErrors()
String getContext()
void pushContextName(String name)
name
- void popContextName()
void throwRTException() throws RecorderException
RecorderException
void reportError(Exception ex) throws RecorderException
ex
- the Exception added.RecorderException
- if too many error messages have been added.void reportError(Exception ex, Object info) throws RecorderException
ex
- the Exception added.info
- extra information (not meant to be part of printed message)RecorderException
- if too many error messages have been added.void reportError(String msg) throws RecorderException
msg
- the text of the error message.RecorderException
- if too many error messages have been added.void reportError(String msg, Object info) throws RecorderException
msg
- the text of the error message.info
- extra information (not meant to be part of printed message)RecorderException
- if too many error messages have been added.void reportWarning(String msg)
msg
- the text of the warning message.void reportWarning(String msg, Object info)
msg
- the text of the warning message.info
- extra information (not meant to be part of printed message)void reportInfo(String msg)
msg
- the text of the info message.Copyright © 2020 Hitachi Vantara. All rights reserved.