boost log库
来源:互联网 发布:python init 编辑:程序博客网 时间:2024/06/05 10:10
这次,尝试filter,首先代码来自于官方文档。
- #include <iostream>
- #include <boost/log/core.hpp>
- #include <boost/log/trivial.hpp>
- #include <boost/log/expressions.hpp>
- namespace logging = boost::log;
- using namespace std;
- void SetFilter() {
- logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
- }
- int main () {
- cout << "hello, world" << endl;
- SetFilter();
- BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
- BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
- BOOST_LOG_TRIVIAL(info) << "An informational severity message";
- BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
- BOOST_LOG_TRIVIAL(error) << "An error severity message";
- BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
- }
当运行程序后,输出结果变了,trac和debug级别的信息被过滤掉了。
- $ ./main
- hello, world
- [2013-12-03 15:34:47.343223] [0x000007f680e76774] [info] An informational severity message
- [2013-12-03 15:34:47.343324] [0x000007f680e76774] [warning] A warning severity message
- [2013-12-03 15:34:47.343341] [0x000007f680e76774] [error] An error severity message
- [2013-12-03 15:34:47.343356] [0x000007f680e76774] [fatal] A fatal severity message
- #include <iostream>
- #include <boost/log/core.hpp>
- #include <boost/log/trivial.hpp>
- #include <boost/log/expressions.hpp>
- namespace logging = boost::log;
- using namespace std;
- void SetFilter1() {
- logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
- }
- void SetFilter2() {
- logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::debug);
- }
- int main () {
- cout << "hello, world" << endl;
- SetFilter1();
- BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
- BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
- BOOST_LOG_TRIVIAL(info) << "An informational severity message";
- BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
- BOOST_LOG_TRIVIAL(error) << "An error severity message";
- BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
- cout << "--------------------" << endl;
- SetFilter2();
- BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
- BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
- BOOST_LOG_TRIVIAL(info) << "An informational severity message";
- BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
- BOOST_LOG_TRIVIAL(error) << "An error severity message";
- BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
- }
- $ ./main
- hello, world
- [2013-12-03 15:37:54.399513] [0x000007fd7709a374] [info] An informational severity message
- [2013-12-03 15:37:54.399612] [0x000007fd7709a374] [warning] A warning severity message
- [2013-12-03 15:37:54.399630] [0x000007fd7709a374] [error] An error severity message
- [2013-12-03 15:37:54.399644] [0x000007fd7709a374] [fatal] A fatal severity message
- --------------------
- [2013-12-03 15:37:54.399666] [0x000007fd7709a374] [debug] A debug severity message
- [2013-12-03 15:37:54.399680] [0x000007fd7709a374] [info] An informational severity message
- [2013-12-03 15:37:54.399693] [0x000007fd7709a374] [warning] A warning severity message
- [2013-12-03 15:37:54.399706] [0x000007fd7709a374] [error] An error severity message
- [2013-12-03 15:37:54.399719] [0x000007fd7709a374] [fatal] A fatal severity message
起作用了。也就是说我们可以在不重新部署程序的情况下修改日志的过滤级别。在我的TCP服务中,可以监听一个管理端口,专门用来接受用于改变过滤级别的特殊消息。
阅读全文
0 0
- Boost log库
- boost log库
- boost log库
- Boost.log库使用方法
- boost log库
- boost log库使用一
- boost log库使用二
- boost log库使用三
- boost log库使用四
- boost log库使用五
- boost log库使用六
- boost log库 使用七
- boost log库 使用十
- boost log库 使用八
- boost log库 使用九
- boost log库 使用十一
- boost::log库,示例代码
- Boost log库的使用
- Web 前端大婶
- 网页中的 <body> 和 <html> 元素及其样式
- PAT (Advanced Level) Practise 1069 The Black Hole of Numbers (20)
- 详解OTT与IPTV的不同之处
- Android camera相机开发拍照功能
- boost log库
- 封装星星评分视图
- Python自动化之select解析
- Resteasy配置及其使用
- Android学习日记(yzy):Service的两种启动
- 求逆矩阵的方法
- springboot集成prometheus
- LightOJ 1106 Gone Fishing(贪心)
- 623. Add One Row to Tree