【问题标题】:Using Poco::Logger for entire project对整个项目使用 Poco::Logger
【发布时间】:2012-12-16 08:17:59
【问题描述】:
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

【问题讨论】:

    标签: c++ logging poco-libraries


    【解决方案1】:

    类 Poco::Logger 用作日志框架。

    当您定义一个具有固定名称的记录器实例(在您的示例中为“LogChan”)时,您的所有类都可以访问它。所以你应该做一个

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

    从您的其他类获取记录器参考。

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

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 2012-12-24
      • 2017-09-25
      • 2016-01-21
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      相关资源
      最近更新 更多