对整个项目使用Poco::Logger

Using Poco::Logger for entire project

本文关键字:Poco Logger 项目      更新时间:2023-10-16
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作为日志框架工作。

当您使用固定的名称(在您的示例中为"LogChan")定义记录器实例时,可以从所有类访问它。所以你应该写一个

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

从其他类中获取记录器引用。

我猜下面它使用单例模式来生成记录器池