2013-01-01 2 views
3
AutoPtr<SplitterChannel> splitterChannel(new SplitterChannel()); 

     AutoPtr<Channel> consoleChannel(new ConsoleChannel()); 
     AutoPtr<Channel> fileChannel(new FileChannel("Arcanite.log")); 
     AutoPtr<FileChannel> rotatedFileChannel(new FileChannel("Arcanite_R.log")); 

     rotatedFileChannel->setProperty("rotation", "100"); 
     rotatedFileChannel->setProperty("archive", "timestamp"); 

     splitterChannel->addChannel(consoleChannel); 
     splitterChannel->addChannel(fileChannel); 
     splitterChannel->addChannel(rotatedFileChannel); 

     //"%d-%m-%Y %H:%M:%S: %t" 
     AutoPtr<Formatter> formatter(new PatternFormatter("%d-%m-%Y %H:%M:%S %s: %t")); 
     AutoPtr<Channel> formattingChannel(new FormattingChannel(formatter, splitterChannel)); 


     Logger& sLog = Logger::create("LogChan", formattingChannel, Message::PRIO_TRACE); 

필자의 서버에 여러 클래스로 사용하려는 로거를 작성했습니다. 어떻게 이렇게 적응할 수 있습니까? 이것은 아마 기본 C + +하지만 몇 가지 수업을 놓친 것 : P전체 프로젝트에 Poco :: Logger 사용

답변

4

클래스 Poco :: 로거는 로깅 프레임 워크로 작동합니다.

고정 된 이름 (예제에서 "LogChan")으로 로거 인스턴스를 정의하면 모든 클래스에서 액세스 할 수 있습니다. 따라서 당신은 로거 참조를 얻기 위해 다른 클래스의

Logger& logger = Logger::get("logChan"); 

을 만들어야합니다.

다음은 로거 풀을 생성하는 데 싱글 톤 패턴을 사용하는 것 같습니다.