Network Deployment (Distributed operating systems), v8.0 > Troubleshoot and support > Add logging and tracing to the application > Program with the JRas framework > Instrumenting an application with JRas extensions


Set up for combined JRas operation

Use JRas operation in combined mode to output trace data and logging messages to both WAS and user-defined logs. The JRas framework described in this task and its sub-tasks is deprecated. However, you can achieve similar results using Java logging. In combined mode, messages and trace are logged to both WAS logs and user-defined logs. The following sample assumes that:


Procedure

  1. Import the requisite JRas extensions classes:
    import com.ibm.ras.*;
    import com.ibm.websphere.ras.*;
    
  2. Import the user handler and formatter:
    import com.ibm.ws.ras.test.user.*;
    
  3. Declare the logger references:
    private RASMessageLogger msgLogger = null;
      private RASTraceLogger trcLogger = null;
    
  4. Obtain a reference to the Manager class, create the loggers, and add the user handlers. Because loggers are named singletons, you can obtain a reference to the loggers in a number of places. One logical candidate for enterprise beans is the ejbCreate method. Make sure that multiple instances of the same user handler are not accidentally inserted into the same logger. Your initialization code must support this approach. The following sample is a message logger sample. The procedure for a trace logger is similar.
    com.ibm.websphere.ras.Manager mgr = com.ibm.websphere.ras.Manager.getManager();
        msgLogger = mgr.createRASMessageLogger("Acme", "WidgetCounter", "RasTest",
               myTestBean.class.getName());
        // Configure the message logger to use the message file defined
        // in the ResourceBundle sample.
        msgLogger.setMessageFile("acme.widgets.DefaultMessages");
    
       // Create the user handler and formatter. Configure the formatter,
       // then add it to the handler.
       RASIHandler handler = new SimpleFileHandler("myHandler", "FileName");
       RASIFormatter formatter = new SimpleFormatter("simple formatter");
        formatter.addEventClass("com.ibm.ras.RASMessageEvent");
        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 updates 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);
    
    
    


JRas manager and logger instances
Set up for integrated JRas operation
Set up for stand-alone JRas operation

+

Search Tips   |   Advanced Search