2010-12-20 5 views
1

우리는 많은 로그를 수집 중입니다. 이러한 로그를 저장하기 위해 데이터베이스 나 파일을 사용하고 텍스트 검색을 사용하여 검색 할 수 있기를 원합니다. 이 작업을 효율적으로 수행 할 수있는 방법이 있습니까?최대 절전 모드 검색 로깅 텍스트 파일

답변

0

그래서 당신이 할 수있어 당신이 루씬 구현 (I 최대 절전 검색을 사용하는 것이 좋습니다)을 생성보다

ExceptionPersistingService eps = new ExceptionPersistingService(); 

try{ 
    //some code that might trow exception 
}catch(Exception e){ 
    eps.saveNewExceptin(getStackTrace(e)); 
} 

public static String getStackTrace(Throwable aThrowable) { 
    //add the class name and any message passed to constructor 
    final StringBuilder result = new StringBuilder("Trace: "); 
    result.append(aThrowable.toString()); 
    final String NEW_LINE = "<br>"; 
    result.append(NEW_LINE); 

    //add each element of the stack trace 
    for (StackTraceElement element : aThrowable.getStackTrace()) { 
     result.append(element); 
     result.append(NEW_LINE); 
    } 
    return result.toString(); 
} 

입니다 것입니다 색인 데이터베이스에 저장된 예외 문자열. save() 메서드에서 ID, Date, ExceptionString, User 및 심지어 URL 세부 사항이 발생한 개체 PersistentException을 만들 수 있습니다.

검색어를 구문 분석하고 퍼지 또는 다른 검색어를 만들고 검색 결과를 즐기기 만하면됩니다. 자세한 내용은 Hibernate Search in ActionLucene in Action과 같은 서적을 공부해야합니다. 제가 간단히 언급 한 것을 수행하는 방법에 대한 좋은 예제가 있습니다.