2011-05-11 5 views
3

부스트 로그의 한 인스턴스로 심각한 파일에 로그인 할 수 있습니까? 내 말은부스트 로그 선택 대상 파일

은 가능한 한 로그를 기록 할 파일을 지정하는 것입니다 :

BOOST_LOG_..(...) << "aaa" <- go to **A.log** 
BOOST_LOG_..(...) << "bbb" <- go to **B.log** 

답변

1

네, 가능 - filters를 사용하여.

당신은 정확하게 당신의 환경에 따라 다르지만 여기 범위 로거 태그 예입니다 방법은 다음과 같습니다

void SomeFunction() 
{ 
    { 
     // everything in this scope gets logged to A.log 
     BOOST_LOG_SCOPED_LOGGER_TAG(lg, "Log", std::string, "LogA") 
     BOOST_LOG(lg) << "aaa"; 
     BOOST_LOG(lg) << "aaa2"; 
    } 

    { 
     // everything in this scope gets logged to B.log 
     BOOST_LOG_SCOPED_LOGGER_TAG(lg, "Log", std::string, "LogB") 
     BOOST_LOG(lg) << "bbb"; 
     BOOST_LOG(lg) << "bbb2"; 
    } 
} 

// This is your log initialization routine 
void InitLogs() 
{ 

    // Initialize sinkA to use a file backend that writes to A.log and sinkB to B.log. 
    // ... 
    // ... 

    // Make sink A only accept records with the Log attribute "LogA" 
    // while sink B will only accept records where it is "LogB". 
    sinkA.set_filter(flt::attr<std::string>("Log") == "LogA"); 
    sinkB.set_filter(flt::attr<std::string>("Log") == "LogB"); 
}