boost日志使用说明
来源:互联网 发布:mac os win10双系统 编辑:程序博客网 时间:2024/05/28 06:06
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/log/support/date_time.hpp>
bool g_nInitLog = false;
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
void InitLog()
{
//输出到文件
auto pSink = logging::add_file_log
(
keywords::open_mode = std::ios::app, //重启程序不删除日志
keywords::file_name = "log/videosnapshow_%N.log",
keywords::rotation_size=10*1024*1024, //超过此大小自动建立新文件
// keywords::time_based_rotation=sinks::file::rotation_at_time_point(0,0,0), //每隔指定时间重建新文件
// This makes the sink to write log records that look like this:
keywords::format =
(
expr::stream
<< expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d, %H:%M:%S.%f")
<< " " << expr::attr< boost::log::aux::thread::id >("ThreadID")
<< ": <" << logging::trivial::severity
<< "> " << expr::smessage
)
);
pSink->locked_backend()->auto_flush(true);//使日志实时更新
//pSink->imbue(std::locale("zh_CN.UTF-8")); // 本地化
logging::add_console_log();
logging::add_common_attributes();
}
使用的时候
void InitLog();
extern bool g_nInitLog;
- 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";
设置过滤也简单。在initlog中设置
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
- boost日志使用说明
- boost库使用说明
- Boost FileSystem 库使用说明2
- log4j日志使用说明
- logback日志使用说明
- boost.pool源码整理和使用说明
- boost.any源码整理和使用说明
- boost.array源码整理和使用说明
- boost.BOOST_STATIC_ASSERT源码整理和使用说明
- boost.shared_ptr源码整理和使用说明
- boost.lexical_cast源码整理和使用说明
- boost.type_traits源码整理和使用说明(1)
- boost.tuple源码整理和使用说明
- windows下boost怎样安装与使用说明
- windows下boost怎样安装与使用说明?
- windows下boost怎样安装与使用说明
- Boost程序库完全开发指南--示例使用说明
- 【Boost】boost库asio详解4——deadline_timer使用说明
- 游戏中的有限状态机
- 关于重新实现TextView 的超链接点击事件
- mysql error 1045 的解决方法
- 【Android学习笔记】ImageView.ScaleType设置图解
- Android进程间通信(IPC)机制Binder简要介绍和学习计划
- boost日志使用说明
- C/C++字符串总结
- Swift 引用计数总结 Strong,Weak, unowned 简单使用
- 编译Redis出错
- 一个可能有用的Python+MQL4混合编程网址
- 界面元模板构件
- Bitmap
- 是否可以删除一个字母之后变成回文串
- Cocos Creator 之 Button使用小结