Boost Log 1
来源:互联网 发布:淘宝买家号能开店吗 编辑:程序博客网 时间:2024/06/06 10:15
Boost Log 基本用法
flyfish 2014-11-5
根据boost提供的代码示例,学习Boost Log 的基本用法
前提
boost版本boost_1_56_0
示例代码文件夹 boost_1_56_0\libs\log\example\basic_usage
使用的单词很形象,整个过程就像流水一样
假设要输出的日志比作水
水 (Hello, World!)
水槽 (sink)
流向哪里 (console,file)
从哪里取 (source)
水的等级 (severity level)
过滤输出 (filter)
格式输出 (format)
各部分连接者(core)
示例
从上到下依次分析
一 日志严重性等级
enum severity_level
{
normal,
notification,
warning,
error,
critical
};
二 日志等级输出
template< typename CharT, typename TraitsT >
inline std::basic_ostream< CharT, TraitsT >& operator<< (
std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
{
...
}
输出已经定义的等级描述,日志等级的数值与字符串一一对应,如果在enum severity_level如果没有定义则输出数值。
std::basic_ostream对所有的内建类型,进行了重载,输入各种内置类型
重载operator <<,使得自定的用户定义类型severity_level 集成到IOStream library中
IOStream library的类都带有两个参数,其中一个是字符的类型,一个是与字符类型相关的信息
就像std::cout一样输出各种类型,编译器自己会进行正确的推导输出的什么类型。
static const char* const 表示数组里面的指针不可改变 而且指针所指向的字符串也不可改变
三 日志输出位置
logging::add_console_log
日志输出到控制台
logging::add_file_log
日志输出到文件
[int __cdecl wmain(int,char *[]) (文件路径:代码行)] <warning> A warning severity message, will pass to the file
2014-11-05, 19:46:19.518082 [00:00:00]
[int __cdecl wmain(int,char *[]) (文件路径:代码行)] <error> An error severity message, will pass to the file
2014-Nov-05 19:51:30.268856: A normal severity message, will not pass to the file
2014-Nov-05 19:51:30.275856: A warning severity message, will pass to the file
2014-Nov-05 19:51:30.284857: An error severity message, will pass to the file
flyfish 2014-11-5
根据boost提供的代码示例,学习Boost Log 的基本用法
前提
boost版本boost_1_56_0
示例代码文件夹 boost_1_56_0\libs\log\example\basic_usage
使用的单词很形象,整个过程就像流水一样
假设要输出的日志比作水
水 (Hello, World!)
水槽 (sink)
流向哪里 (console,file)
从哪里取 (source)
水的等级 (severity level)
过滤输出 (filter)
格式输出 (format)
各部分连接者(core)
示例
从上到下依次分析
一 日志严重性等级
enum severity_level
{
normal,
notification,
warning,
error,
critical
};
二 日志等级输出
template< typename CharT, typename TraitsT >
inline std::basic_ostream< CharT, TraitsT >& operator<< (
std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
{
...
}
输出已经定义的等级描述,日志等级的数值与字符串一一对应,如果在enum severity_level如果没有定义则输出数值。
std::basic_ostream对所有的内建类型,进行了重载,输入各种内置类型
重载operator <<,使得自定的用户定义类型severity_level 集成到IOStream library中
IOStream library的类都带有两个参数,其中一个是字符的类型,一个是与字符类型相关的信息
就像std::cout一样输出各种类型,编译器自己会进行正确的推导输出的什么类型。
static const char* const 表示数组里面的指针不可改变 而且指针所指向的字符串也不可改变
三 日志输出位置
logging::add_console_log
日志输出到控制台
logging::add_file_log
日志输出到文件
四 定义源,像std::cout一样输出
src::logger lg;
BOOST_LOG(lg) << "Hello, World!";五 结果
文件的输出
2014-11-05, 19:46:19.513082 [00:00:00][int __cdecl wmain(int,char *[]) (文件路径:代码行)] <warning> A warning severity message, will pass to the file
2014-11-05, 19:46:19.518082 [00:00:00]
[int __cdecl wmain(int,char *[]) (文件路径:代码行)] <error> An error severity message, will pass to the file
控制台的输出
2014-Nov-05 19:51:30.261856: Hello, World!2014-Nov-05 19:51:30.268856: A normal severity message, will not pass to the file
2014-Nov-05 19:51:30.275856: A warning severity message, will pass to the file
2014-Nov-05 19:51:30.284857: An error severity message, will pass to the file
0 0
- Boost Log 1
- boost log
- boost::log
- Boost.log的编译
- Boost.log的应用
- Boost.log的应用
- Boost log库
- boost log库
- boost log 中的几个问题
- BOOST Log 使用 Unicode
- boost.log要点笔记
- boost log库
- Boost Log 基本用法
- Boost log 简单使用
- boost log 和 log4cplus
- boost log 使用问题
- Boost.log的应用
- boost.log要点笔记
- 最大子矩阵(动态规划)
- LeetCode Swap Nodes in Pairs
- netty中LengthFieldBasedFrameDecoder的使用
- 使用IntelliJ IDEA开发SpringMVC网站(五)博客文章管理
- 表白吧!程序猿!
- Boost Log 1
- 【剑指offer】Excel2003中,用A表示第一列,B表示第二列,。。Z表示第26列,AA表示27列,AB表示第28列
- Spring源码分析【4】-Spring扫描basePackages注解
- LSP网络监控
- DragonBoard 410c平台web服务器的移植
- 将json转换为MySql语句
- 【1】Two Sum
- PractByzantFaTolece Algo
- git grep 命令搜索关键词