c++ - 对整个项目使用 Poco::Logger

标签 c++ logging poco-libraries

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/

相关文章:

c++ - 如何正确关闭与 Poco::HTTPSClientSession 的连接?

c++ - Windows 消息过程的函数指针数组

C++:我可以在函数调用期间将 vector <derived_class> 转换为 vector <base_class> 吗?

linux - 每次滚动或旋转我的日志文件时,如何使用 'newsyslog' 触发脚本?

java - AWS 使用 SLF4J 记录单独的日志文件

reactjs - 在正确(?)安装和使用后,Loglevel 未登录我的 React 应用程序

c++ - Poco::Net HTTPServer:如何检测断开连接的客户端?

c++ - 在 0x00007FF93E507A7A (ntdll.dll) 处抛出异常。访问冲突读取位置 0xFFFFFFFFFFFFFFFF

c++ - 在调试中无法从 'const char *'转换为 'LPCTSTR'

c++ - 这个头文件是什么意思(virtual const char* what() const throw())?