编译boost:

1、打开Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Promot

2、命令CD到boost目录下,运行 bjam stage --toolset=msvc-10.0 --with-log threading=multi release

stage 指编译到stage目录下,toolset:编译工具,with-log:指定编译boost的log模块

Log 模块:

boost log库 使用

 #include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/thread/thread.hpp>
#include <boost/log/core.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/formatter_parser.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/attributes/named_scope.hpp>
#include <boost/log/expressions/keyword.hpp> #include <fstream>
#include <iostream> using namespace std; namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords; using namespace logging::trivial; enum sign_severity_level {
trace,
debug,
info,
warning,
error,
fatal,
report
}; BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::severity_logger_mt<sign_severity_level>) void InitLog()
{
typedef sinks::synchronous_sink<sinks::text_file_backend> TextSink; // 设置旋转日志,每天0时添加一个日志文件,或日志文件大于10MB时添加另一个日志文件,磁盘必须大于3G
/*boost::shared_ptr<sinks::text_file_backend>*/
auto backend = boost::make_shared<sinks::text_file_backend>(
keywords::file_name = "%Y-%m-%d.log", // 日志文件
keywords::rotation_size = * * , // 日志文件上限10MB
keywords::time_based_rotation = sinks::file::rotation_at_time_point(, , ), // 每天一个日志文件
keywords::min_free_space = * * , // 磁盘最小容量
keywords::open_mode = ios::app, // 文件追加
keywords::auto_flush = true // 自动刷新(立刻写入日志文件)
); //// 自动刷新(立刻写入日志文件)
//backend->auto_flush(true); boost::shared_ptr<TextSink> sink(new TextSink(backend)); // 格式化日志格式 [日期]<日志级别>: 日志内容
sink->set_formatter(
//// 两种格式化写法
//// 1:
//expr::stream
//<< "[" << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << "]"
//<< "<" << expr::attr<SeverityLevel::sign_severity_level>("Severity") << ">"
//<< "(" << expr::format_named_scope("Scopes", boost::log::keywords::format = "%n (%f : %l)") << "):"
//<< expr::smessage // 2:
expr::format("[%1%]<%2%>(%3%): %4%")
% expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S")
% expr::attr<sign_severity_level>("Severity") /*logging::trivial::severity*/
// %n:Scope name(void foo());%f:Source file name of the scope;%l:Line number in the source file
% expr::format_named_scope("Scopes", boost::log::keywords::format = "%n (%f : %l)")
//% expr::attr<attrs::current_thread_id::value_type >("ThreadID") // 单线程没有ID
% expr::smessage
); logging::core::get()->add_global_attribute("Scopes", attrs::named_scope()); // 设置过滤器
sink->set_filter(expr::attr< sign_severity_level >("Severity") >= sign_severity_level::error);
//sink->set_filter(expr::attr< severity_level >("Severity") >= logging::trivial::severity_level::error); logging::add_common_attributes(); // 要添加,否则线程ID和日期等一些属性都打印不出来
logging::core::get()->add_sink(sink);
} void foo(void)
{
//BOOST_LOG_FUNCTION(); // 打印更详细的scope BOOST_LOG_NAMED_SCOPE("Scopes"); // 一定要这句,否则打印不出scope
src::severity_logger_mt<sign_severity_level>& lg = my_logger::get();
BOOST_LOG_SEV(lg, sign_severity_level::error) << "A trace severity message";
} int main()
{
InitLog();
foo();
logging::core::get()->remove_all_sinks();
}

Boost log样例

boost 相关的更多相关文章

  1. boost相关

    1 boost 常用函数 <1> tcp跟udp的收发函数名 tcp收发 async_write async_read async_read_until udp收发 async_send_ ...

  2. 编译用到boost相关的东西,问题的解决;以及和googletest库

    编译https://github.com/RAttab/reflect, 发现需要gcc4.7以上的版本才行.于是编译安装最新的gcc-6.2.0, 过程算顺利. http://www.linuxfr ...

  3. Boost程序库完全开发指南——深入C++“准”标准库(第3版)

    内容简介  · · · · · · Boost 是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库,有着“C++‘准’标准库”的美誉. Boost 由C++标准委员会部分成员所设立的Bo ...

  4. boost function对象

    本文根据boost的教程整理. 主要介绍boost function对象的用法. boost function boost function是什么 boost function是一组类和模板组合,用于 ...

  5. boost 的函数式编程库 Phoenix入门学习

    这篇文章是我学习boost phoenix的总结. 序言 Phoenix是一个C++的函数式编程(function programming)库.Phoenix的函数式编程是构建在函数对象上的.因此,了 ...

  6. Gradient Boost 算法流程分析

    我们在很多Gradient Boost相关的论文及分析文章中都可以看到下面的公式: 但是,对这个公式的理解,我一直也是一知半解,最近,终于下决心对其进行了深入理解. 步骤1:可以看作优化目标的损失函数 ...

  7. 并发编程(二):分析Boost对 互斥量和条件变量的封装及实现生产者消费者问题

    请阅读上篇文章<并发编程实战: POSIX 使用互斥量和条件变量实现生产者/消费者问题>.当然不阅读亦不影响本篇文章的阅读. Boost的互斥量,条件变量做了很好的封装,因此比" ...

  8. Boost 和 Boost.Build 的设置

    问题: 安装编译完 Boost 后,如果不设置 BOOST_ROOT 和 BOOST_BUILD_PATH 则可能导致使用 bjam 时定位到 Boost 默认的路径 /usr/share/boost ...

  9. 比特币源码分析--C++11和boost库的应用

    比特币源码分析--C++11和boost库的应用     我们先停下探索比特币源码的步伐,来分析一下C++11和boost库在比特币源码中的应用.比特币是一个纯C++编写的项目,用到了C++11和bo ...

随机推荐

  1. linux中文显示乱码的解决办法

    linux中文显示乱码的解决办法 linux中文显示乱码是一件让人很头疼的事情. linux中文显示乱码的解决办法:[root@kk]#vi /etc/sysconfig/i18n将文件中的内容修改为 ...

  2. WordPress 主题开发 - (六) 创建主题函数 待翻译

    We’ve got a file structure in place, now let’s start adding things to them! First, we’re going to ad ...

  3. RSA的密钥把JAVA格式转换成C#的格式

    RSA算法在C#与JAVA之前的交互 在JAVA生成一对RSA私钥和公钥的时候,是以下的形式给到C#去调用: string publickey = @"MIGfMA0GCSqGSIb4DQE ...

  4. 一幅图证明chrome的由来和目的

  5. hdu 5427 A problem of sorting

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5427 A problem of sorting Description There are many ...

  6. hdu 5272 Dylans loves numbers

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...

  7. hdu 1890 Robotic Sort

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1890 如下: #include<cstdio> #include<cstdlib&g ...

  8. swift学习初步(四)-- 函数

    好了,让我们开始接着前几天写的系列博客开始今天的这篇博客.在swift里面如果你需要定义一个方法的话,你需要使用关键字:func,请看下面的这段代码: func sayHello(name:Strin ...

  9. jquery方法回到顶部代码

    <style> /*默认样式,主要是position:fixed实现屏幕绝对定位*/ #gotoTop{display:none;position:fixed;top:75%;left:5 ...

  10. [转]Linux Ubuntu上架设FTP

    Linux Ubuntu上架设FTP http://www.blogjava.net/stonestyle/articles/369104.html 操作系统:ubuntu (GNU/Linux) 为 ...