Creating manager and logger instances

This section provides sample code in which message loggers and trace loggers are obtained in the main method of a standalone application. To obtain a logger, you first obtain a manager by calling the getManager method on the com.ibm.websphere.ras.Manager class. You then obtain a message logger by calling createRASIMessageLogger on the returned manager object, or a trace logger by calling createRASITraceLogger on the returned manager object. Figure 2 demonstrates these methods.

Figure 2. Example code: Obtaining a manager, a message logger, and a trace logger


// Import the appropriate JRas and WebSphere packages
import com.ibm.ras.*;
import com.ibm.websphere.ras.*;
// Declare the logger attributes and a group name for trace loggers. The storage
// scope used here depends on the application.
static RASITraceLogger trcLogger = null;
static RASIMessageLogger msgLogger = null;
// Define some convenience strings
static String svOrg = "My organization name";
static String svProd = "My product name";
static String svComponent = "My component name";
static String svClassName = "Fully qualified class name";
static java.lang.String groupName = "MyProduct_someGroup";
...
public static void main(String[] argv)
{
// Get a reference to the Manager instance and create the loggers.
// Because "Manager" is a common term, fully qualify it to ensure we
// get the right one.
com.ibm.websphere.ras.Manager mgr = com.ibm.websphere.ras.Manager.getManager();
msgLogger = mgr.createRASIMessageLogger(svOrg, svProd, svComponent, svClassName);
trcLogger = mgr.createRASITraceLogger(svOrg, svProd, svComponent, svClassName);
// Configure the message logger with the default resource bundle
msgLogger.setMessageFile("subDir1.subDir2.resources.DefaultMessages");
// Add the trace logger to a group
mgr.addLoggerToGroup(trcLogger, groupName);
}