Logging 如何使用Poco记录器

Logging 如何使用Poco记录器,logging,global,poco,Logging,Global,Poco,我是Poco新手,我在Poco联机帮助中看到了以下示例: int main(int argc, char** argv) { AutoPtr<SimpleFileChannel> pChannel(new SimpleFileChannel); pChannel->setProperty("path", "sample.log"); pChannel->setProperty("rotation", "2 K"); Logger::root

我是Poco新手,我在Poco联机帮助中看到了以下示例:

int main(int argc, char** argv)
{
    AutoPtr<SimpleFileChannel> pChannel(new SimpleFileChannel);
    pChannel->setProperty("path", "sample.log");
    pChannel->setProperty("rotation", "2 K");
    Logger::root().setChannel(pChannel);
    Logger& logger = Logger::get("TestLogger"); // inherits root channel
    for (int i = 0; i < 100; ++i)
        logger.information("Testing SimpleFileChannel");
    return 0;
}
Logger::get()
是否授予对
Logger
对象的全局池的访问权限(作为一个单例)

如果您运行上面的代码段,即在
main()
中初始化记录器并通过
logger::get(“TestLogger”)
myClass::myFun()
中引用记录器,会发生什么情况?那应该行得通

当然,您无权访问
myClass::myFun()
中的
main()
s
Logger&
引用,但您应该能够通过
Logger::get()
访问它

class myClass
{
public:
     myClass() { }
     ~myClass() { }
     myFun() { /*calling logger...*/ } 
};

int main(int argc, char** argv)
{
    AutoPtr<SimpleFileChannel> pChannel(new SimpleFileChannel);
    pChannel->setProperty("path", "sample.log");
    pChannel->setProperty("rotation", "2 K");
    Logger::root().setChannel(pChannel);
    Logger& logger = Logger::get("TestLogger"); // inherits root channel
    logger.information("starting up");

    myClass aClass;
    aClass.myFun();
    return 0;
}