JRas 管理器和记录器实例
您可使用集成、独立或组合方式下的 JRas 扩展。应用程序的配置将随着操作方式不同而不同,但是在所有操作方式下使用记录器来记录消息条目或跟踪条目都是相同的。
不推荐使用:不推荐使用本任务及其子任务中描述的 JRas 框架。但是,可以使用 Java™ 记录来获得类似结果。
集成的方式是缺省操作方式。使用此方式时,消息和跟踪事件将发送到 WebSphere® Application Server 日志。
使用组合方式时,消息和跟踪事件将记录到 WebSphere Application Server 日志和用户定义的日志中。
独立方式中,消息和跟踪事件仅记录到用户定义的日志中。
使用消息和跟踪记录器
无论是什么操作方式,消息和跟踪记录器的使用是相同的。
使用消息记录器
消息记录器被配置为使用 DefaultMessages 资源束。如果记录器正在使用消息 API,那么必须将消息密钥传递给消息记录器。
msgLogger.message(RASIMessageEvent.TYPE_WARNING, this, methodName, "MSG_KEY_00"); ... msgLogger.message(RASIMessageEvent.TYPE_WARN, this, methodName, "MSG_KEY_01", "some string");
如果消息记录器使用 msg API,那么可以指定新的资源束名称。
msgLogger.msg(RASIMessageEvent.TYPE_ERR, this, methodName, "ALT_MSG_KEY_00", "alternateMessageFile");
您也可以记录文本消息。如果正在使用 textMessage API,那么不会对消息排列格式。
msgLogger.textMessage(RASIMessageEvent.TYPE_INFO, this, methodName,"String and Integer", "A String", new Integer(5));
使用跟踪记录器
因为跟踪通常会被禁用,所以应保护跟踪方法以提高性能。
private void methodX(int x, String y, Foo z)
{
// trace an entry point. Use the guard to make sure tracing is enabled.
Do this checking before you gather parameters to trace.
if (trcLogger.isLoggable(RASITraceEvent.TYPE_ENTRY_EXIT) {
// I want to trace three parameters, package them up in an Object[]
Object[] parms = {new Integer(x), y, z};
trcLogger.entry(RASITraceEvent.TYPE_ENTRY_EXIT, this, "methodX", parms);
}
... logic
// a debug or verbose trace point
if (trcLogger.isLoggable(RASITraceEvent.TYPE_MISC_DATA) {
trcLogger.trace(RASITraceEvent.TYPE_MISC_DATA, this, "methodX" "reached here");
}
...
// Another classification of trace event. An important state change is
detected, so a different trace type is used.
if (trcLogger.isLoggable(RASITraceEvent.TYPE_SVC) {
trcLogger.trace(RASITraceEvent.TYPE_SVC, this, "methodX", "an important event");
}
...
// ready to exit method, trace. No return value to trace
if (trcLogger.isLoggable(RASITraceEvent.TYPE_ENTRY_EXIT)) {
trcLogger.exit(RASITraceEvent.TYPE_ENTRY_EXIT, this, "methodX");
}
}