Poco::日志的配置文件属性
来源:互联网 发布:人类起源于中国知乎 编辑:程序博客网 时间:2024/06/05 20:50
版权所有,转载时请注明作者和出处 http://blog.csdn.net/jmppok/article/details/25598483Poco是一个开源的C++库,各方面功能比较全面,包括日志\多线程\文件系统\定时器\网络\配之文件等,同时使用也十分简单.本文对其中的日志模块进行了简单的试用.1.使用示例[cpp] view plain copy 在CODE上查看代码片派生到我的代码片Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> pConf = new Poco::Util::PropertyFileConfiguration("log_conf.properties"); Poco::Util::LoggingConfigurator log_configurator; log_configurator.configure(pConf); _log = &Poco::Logger::root(); _log->debug("debug"); _log->information("information"); _log->warning("warning"); _log->error("error"); _log->fatal("fatal"); 在代码中使用十分简单。2.Log的配置文件以上代码通过加载配置文件log_conf.propeties对其进行配置。Poco本身对log配置文件似乎没有详细说明,不过可以通过阅读源代码总结出来。 下面是我整理的一个配置文件,其内容如下:[cpp] view plain copy 在CODE上查看代码片派生到我的代码片logging.formatters.f1.class = PatternFormatter logging.formatters.f1.pattern = [%p %Y-%m-%d %H:%M:%S %i %P %I]\n%U:%u\n%t logging.channels.c1.class = ConsoleChannel logging.channels.c1.formatter = f1 logging.channels.c2.class = FileChannel logging.channels.c2.formatter = f1 logging.channels.c2.path = ./sample.log logging.channels.c2.rotation = daily logging.channels.splitter.class = SplitterChannel logging.channels.splitter.channels = c1,c2 logging.loggers.root.channel = splitter logging.loggers.root.level = debug 可以看到配置文件分为5个部分:1) 前两行 定义了一个formatter,就是定义了日志的输出格式:[%p %Y-%m-%d %H:%M:%S %i %P %I]\n%U:%u\n%t 2)接下来两行定义了一个输出通道,输出的Console控制台,输出格式就是上面定一个的f1 3) 接下来4行定义了另一个输出通道,输出到文件,文件名是sample.log, 输出格式也是f1,。logging.channels.c2.rotation = daily rotation=daily意思是每天写一个文件。当然还可以设定文件大小,保存天数等。 具体可看最后的参考文章。4) 接下来两行,把2) 3)定义的两个输出通道组合起来,成为一个splitter的通道。5)最后两行,将splitter通道设定为日志root的通道,这样输出的日志会通过splitter分别送到console 和 file。 最后定义日志输出级别为debug。
0 0
- Poco::日志的配置文件属性
- POCO: 日志的使用
- Poco Application 框架学习(3)配置文件,日志
- Poco C++ 简单的日志封装
- POCO开源库的日志使用示例
- spring日志 ---获取配置文件属性的三个方法
- Poco 配置文件读取
- POCO日志框架
- Poco 日志 之 系统日志
- 【Poco】Poco::StringTokenizer的例子
- 【Poco】Poco::LocalDateTime的例子
- 【Poco】Poco::UUIDGenerator的例子
- 【Poco】Poco::Any的例子
- 【Poco】Poco::AutoPtr的例子
- 【Poco】Poco::AutoReleasePool的例子
- 【Poco】Poco::BypeOrder的例子
- 【Poco】Poco::DynamicFactory的例子
- 【Poco】Poco::Format的例子
- 孙鑫视频VC++深入详解学习笔记
- 选择数字(动态规划+单调队列)
- Redis实战之征服 Redis + Jedis + Spring (二)
- 100万奖金加持,“智慧中国杯”全国大数据创新应用大赛上线
- Linux 下修改系统当前时间
- Poco::日志的配置文件属性
- kubernetes1.5新特性跟踪
- 正则表达式过滤掉大小写字母,数字,标点符号,空格
- 有关Clang
- ServletContextListener、ServletRequestListener
- centos发邮件
- @PostConstruct注解
- 利用RxJava实现的事件总线(Event Bus)
- Redis实战之征服 Redis + Jedis + Spring (三)