2013-03-26 3 views
1

내 응용 프로그램에는 cxf 프레임 워크의 도움으로 구현 된 여러 웹 서비스가 있습니다. 각 웹 서비스의 들어오는 요청을 별도의 파일에 기록하고 싶습니다. 예 : 순간 CXF는 특정 파일에 로그를 작성합니다.

requests -> ws1 interface -> incomingWs1.log 
requests -> ws2 interface -> incomingWs2.log 

은 내가 로깅 인터셉터와 수신 및 발신 메시지를 기록하는 방법을 알고있다. 이 잘 작동하지만 interceports 함께 로그의 출력 위치를 정의 할 수 없습니다. 여기에 로깅 인터셉터를 사용하여 샘플은 다음과 같습니다

@WebService(endpointInterface = "at.pdts.cxf.HelloWorld") 
@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor") // this works! 
@Logging(limit=16000, inLocation="<stdout>", outLocation="<logger>", pretty=true) // does not work! 
public class HelloWorldImpl implements HelloWorld { ... 

동안 연구 한 후 위의 코드 샘플에서 볼 수 있듯이, 내가 검색 한 위치 설정을 제공하는 로깅 주석을 발견했다. annation에는 효과가 없습니다!

file:///c:/log.log 
file:c:\log.log 
<stdout> 

몇 가지 위치 옵션을 시도했습니다. 누군가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다. Grails 2.2.1 버전에서 cxf 프레임 워크 2.7.3을 사용하고 있습니다.

답변

0

솔루션은 매우 간단합니다. 로깅 주석을 사용하려면 서비스 엔드 포인트 인터페이스에 배치해야합니다. 내가 주석 위에 게시 된 예에서하여 HelloWorld 인터페이스에 속하는 :

@Logging(limit=16000, inLocation="<stdout>", outLocation="<logger>", pretty=true) 
public interface HelloWorld { 
... 

사용하는 파일은 특정 파일, 예를 들어,에있는 비누 메시지를 기록하는 URI file : /// c : /out.txt.

1

속성은 @Logging 주석을 사용하여이를 달성 할 수 있지만 제공된 파일 이름은 절대 파일 이름이어야합니다. URI 내부적으로 AbstractLoggingInterceptor 클래스 내에서 출력 파일을 만드는 데 사용하고 있기 때문에 아래 그림과 같이 오직 절대 경로가 작동합니다

@Logging(limit=16000, inLocation="<stdout>", outLocation="/absolute/path/to/file", pretty=true) 
public class HelloWorldImpl implements HelloWorld { ... 

주 : 예는 아래에 제공되는

public abstract class AbstractLoggingInterceptor extends AbstractPhaseInterceptor<Message> { 
    public void setOutputLocation(String s) { 
     ... 
     } else { 
      try { 
       URI uri = new URI(s); 
       File file = new File(uri); 
       writer = new PrintWriter(new FileWriter(file, true), true); 
      } catch (Exception ex) { 
       getLogger().log(Level.WARNING, "Error configuring log location " + s, ex); 
      } 
     } 
    } 
} 

당신이 만약 런타임에 이름이 결정되는 동적 파일을 사용하려면 LoggingOutInterceptor을 확장하여이를 수행 할 수 있습니다.

관련 문제