POCO: 日志的使用
来源:互联网 发布:excel显示无法粘贴数据 编辑:程序博客网 时间:2024/06/05 09:08
最简单的使用
#include "Poco/Logger.h"#include "Poco/AutoPtr.h"#include "Poco/ConsoleChannel.h"int main(){ /* 1.获取 root logger */ auto &logger = Poco::Logger::root(); /* 2.设置管道 */ Poco::AutoPtr<Poco::ConsoleChannel> consoleChannel(new Poco::ConsoleChannel); logger.setChannel(consoleChannel); /* 3.打印日志 */ poco_error(logger, "This is an error message"); return 0;}
利用 Formatter 格式化输出
#include "Poco/Logger.h"#include "Poco/AutoPtr.h"#include "Poco/ConsoleChannel.h"#include "Poco/PatternFormatter.h"#include "Poco/FormattingChannel.h"int main(){ /* 1.获取 root logger */ auto &logger = Poco::Logger::root(); /* 2.设置管道 */ /* 2.1 创建控制台管道 */ Poco::AutoPtr<Poco::ConsoleChannel> consoleChannel(new Poco::ConsoleChannel); /* 2.2 创建 Formatter */ // 关于格式化控制符的说明可以参见 PatternFormatter.h 中的描述 Poco::AutoPtr<Poco::PatternFormatter> patternFormatter( new Poco::PatternFormatter("[%H:%M:%S] [%U(%u)] %p: %t")); patternFormatter->setProperty("times", "local"); // 格式化中的时间显示为本地时间 /* 2.3 创建 Formatting Channel */ Poco::AutoPtr<Poco::FormattingChannel> formattingChannel( new Poco::FormattingChannel(patternFormatter, consoleChannel)); /* 2.4 将 Formatting Channel 设置给 logger */ logger.setChannel(formattingChannel); /* 3.打印日志 */ poco_error(logger, "This is an error message"); return 0;}
从配置文件读取配置
关于如何写配置文件请见 LoggingConfigurator.h 中的描述。
关于如何写 FileChannel 请见 FileChannel.h 中的描述。
logging.loggers.root.channel = splitterlogging.loggers.root.level = tracelogging.formatters.f1.class = PatternFormatterlogging.formatters.f1.pattern = [%H:%M:%S] [%U(%u)] %p: %tlogging.formatters.f1.times = locallogging.channels.c1.class = ConsoleChannellogging.channels.c1.formatter = f1logging.channels.c2.class = FileChannellogging.channels.c2.path = message.loglogging.channels.c2.formatter = f1logging.channels.c2.rotation = 10Klogging.channels.c2.archive = timestamplogging.channels.c2.times = locallogging.channels.c2.purgeCount = 10logging.channels.c2.compress = truelogging.channels.splitter.class = SplitterChannellogging.channels.splitter.channels = c1, c2
#include "Poco/AutoPtr.h"#include "Poco/Util/PropertyFileConfiguration.h"#include "Poco/Util/LoggingConfigurator.h"#include "Poco/Exception.h"#include "Poco/Logger.h"#include "Poco/PatternFormatter.h"int main(){ try { Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> propertyFileConfiguration( new Poco::Util::PropertyFileConfiguration("log.properties")); Poco::Util::LoggingConfigurator().configure(propertyFileConfiguration); } catch (Poco::Exception &e) { std::cerr << e.displayText() << std::endl; return -1; } auto &logger = Poco::Logger::root(); poco_error(logger, "This is an error message"); poco_debug(logger, "This is a debug message"); poco_fatal(logger, "This is a fatal error!"); system("pause"); return 0;}
阅读全文
1 0
- POCO: 日志的使用
- POCO开源库的日志使用示例
- POCO日志库使用示例
- Poco::日志的配置文件属性
- POCO库的使用
- poco JSON 的使用
- 使用Poco::Logger实现日志功能
- Poco C++ 日志框架使用 Pcoco Logger
- Poco logger 日志使用小析
- Poco C++ 简单的日志封装
- Poco使用SQLite的事务
- POCO日志框架
- Poco 日志 之 系统日志
- Poco中插件的使用范例
- Poco c++ Library 之xml 的使用
- POCO C++ 在IOS上的使用
- poco中的进程使用的纠结
- poco for ARM的安装及使用
- alter table move跟shrink space的区别
- IDEA 快捷键
- PBOC规范研究之一、ISO14443协议和PBOC关于CID的约定
- POJ-3614--贪心+优先队列---Sunscreen
- 《游戏设计艺术》:Hello
- POCO: 日志的使用
- 实现带header和footer功能的RecyclerView
- 07-21XML
- python获取Oracle的列名
- MFC编辑框自动换行,垂直滚动条自动下移
- 信源编码第五次作业-LMS最小均方算法
- java通配符
- pandas读取csv处理时报错:ParserError: Error tokenizing data. C error: Expected 1 fields in line 29, saw 2
- redis cluster & sqirrel的一些学习