ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzamy_5.4.0.1/50/program/jrasets.htm

89 lines
3.3 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<LINK rel="stylesheet" type="text/css" href="../../../rzahg/ic.css">
<title>Set up for standalone JRas operation</title>
</head>
<BODY>
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../../../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h6><a name="jrasets"></a>Set up for standalone JRas operation</h6>
<p>In standalone mode, messages and traces are logged only to user-defined logs. The following sample
assumes that you have a user-defined handler named SimpleFileHandler and a user-defined formatter named
SimpleFormatter. It is also assumes that no user-defined types or events are being used.</p>
<ol>
<li>Import the requisite JRas extensions classes:
<pre>
import com.ibm.ras.*;
import com.ibm.websphere.ras.*;
</pre>
</li>
<li>Import the user handler and formatter:
<pre>
import com.ibm.ws.ras.test.user.*;
</pre>
</li>
<li>Declare the logger references:
<pre>
private RASMessageLogger msgLogger = null;
private RASTraceLogger trcLogger = null;
</pre>
</li>
<li>Obtain a reference to the Manager, create the loggers and add the user handlers.
<p>Since loggers are named singletons, you can obtain a reference to the loggers in a number of places.
One logical candidate for servlets is the servlet init() method. Make sure that multiple instances of
the same user handler are not accidentally inserted into the same logger. Your initialization code must
handle this. The following sample is a message logger sample. The procedure for a trace logger is
similar.</p>
<pre>
com.ibm.websphere.ras.Manager mgr = com.ibm.websphere.ras.Manager.getManager();
msgLogger = mgr.createRASMessageLogger(&quot;Acme&quot;, &quot;WidgetCounter&quot;,
&quot;RasTest&quot;, myTestServlet.class.getName());
// Configure the message logger to use the message file
// defined in the ResourceBundle sample.
msgLogger.setMessageFile(&quot;acme.widgets.DefaultMessages&quot;);
// Get a reference to the Handler and remove it from the logger.
RASIHandler aHandler = null;
Enumeration enum = msgLogger.getHandlers();
while (enum.hasMoreElements()) {
aHandler = (RASIHandler)enum.nextElement();
if (aHandler instanceof WsHandler)
msgLogger.removeHandler(wsHandler);
}
// Create the user handler and formatter. Configure the formatter,
// then add it to the handler.
RASIHandler handler = new SimpleFileHandler(&quot;myHandler&quot;, &quot;FileName&quot;);
RASIFormatter formatter = new SimpleFormatter(&quot;simple formatter&quot;);
formatter.addEventClass(&quot;com.ibm.ras.RASMessageEvent&quot;);
handler.addFormatter(formatter);
// Add the Handler to the logger. Add the logger to the list of the
// handlers listeners, then set the handlers
// mask, which will update the loggers composite mask appropriately.
// WARNING - there is an order dependency here that must be followed.
msgLogger.addHandler(handler);
handler.addMaskChangeListener(msgLogger);
handler.setMessageMask(RASIMessageEvent.DEFAULT_MESSAGE_MASK);
</pre>
</li>
</ol>
</body>
</html>