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++,但我似乎错过了一些类(class) :P
最佳答案
Poco::Logger 类用作日志记录框架。
当您定义一个具有固定名称(在您的示例中为“LogChan”)的记录器实例时,它可以从您的所有类访问。所以你应该做一个
Logger& logger = Logger::get("logChan");
从您的其他类获取记录器引用。
我猜下面它使用单例模式来生成记录器池。
关于c++ - 对整个项目使用 Poco::Logger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14114014/