결합 모드에서 JRas 조작을 사용하여
추적 데이터 및 로깅 메시지를 WebSphere® Application Server 및 사용자 정의 로그 둘 다에 출력할 수 있습니다.
시작하기 전에
이 태스크 및 하위 태스크에서 설명하는 JRas 프레임워크는 더 이상 사용되지 않습니다. 그러나 Java™ 로깅을 사용하여 유사한 결과를 얻을 수 있습니다.
이 태스크 정보
결합 모드에서 메시지 및 추적은 WebSphere Application
Server 로그 및 사용자 정의 로그에 모두 로그됩니다. 다음 샘플에서는 다음과 같이 가정합니다.
- SimpleFileHandler라는 이름의 사용자 정의 핸들러 및 SimpleFormatter라는 이름의 사용자 정의 포맷터를 작성했습니다.
- 사용자 정의 유형 또는 이벤트를 사용하지 않습니다.
프로시저
- 다음과 같이 필수 JRas 확장 클래스를 가져오십시오.
import com.ibm.ras.*;
import com.ibm.websphere.ras.*;
- 다음과 같이 사용자 핸들러 및 포맷터를 가져오십시오.
import com.ibm.ws.ras.test.user.*;
- 다음과 같이 로거 참조를 선언하십시오.
private RASMessageLogger msgLogger = null;
private RASTraceLogger trcLogger = null;
- 관리자 클래스에 대한 참조를 얻고 로거를 작성하고 사용자 핸들러를 추가하십시오. 로거는 싱글톤으로 이름 지정되므로 여러 위치에서 로거에 대한 참조를 얻을 수 있습니다. 엔터프라이즈 Bean에 대한 한 개의 논리 후보는
ejbCreate 메소드입니다. 동일한 사용자 핸들러의 여러 인스턴스가 실수로 같은 로거에 삽입되지 않도록 하십시오. 초기화 코드가 이 접근법을
지원해야 합니다. 다음 샘플은 메시지 로거 샘플입니다. 추적 로거에 대한 프로시저는 비슷합니다.
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);