POCO开源库的日志使用示例

来源:互联网 发布:大数据培训ujiuye 编辑:程序博客网 时间:2024/06/06 01:32
#include "Poco/Logger.h"#include "Poco/FormattingChannel.h"#include "Poco/PatternFormatter.h"#include "Poco/FileChannel.h"#include "Poco/Message.h"using Poco::Logger;using Poco::PatternFormatter;using Poco::FormattingChannel;using Poco::FileChannel;using Poco::Message;#pragma comment(lib,"PocoFoundationd.lib")int main(){FormattingChannel *pFCFile = NULL;pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%d %H:%M:%S.%c %U %u %N[%P]:%s:%q:%t"));pFCFile->setChannel(new FileChannel("./sample.log"));pFCFile->open();Logger &fileLogger = Logger::create("FileLogger", pFCFile, Message::PRIO_DEBUG);fileLogger.debug("an debug msg!", "main.cpp", 24);//24表示行号fileLogger.information("an info msg!");fileLogger.error("an error msg!");fileLogger.fatal("an fatal msg!");pFCFile->close();return 0;}

0 0
原创粉丝点击