[ 跟进检查boost :: log过滤器明确? ]
以下示例使用Boost Log中的普通记录器.它输出1,显示expensive()只调用一次.它是如何工作的?为什么expensive()不叫?
#include <iostream>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
int count = 0;
int expensive()
{
return ++count;
}
int main()
{
boost::log::core::get()->set_filter(
boost::log::trivial::severity >= boost::log::trivial::warning
);
BOOST_LOG_TRIVIAL(error) << expensive();
BOOST_LOG_TRIVIAL(info) << expensive();
std::cout << count << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
[2018-05-21 14:33:47.327507] [0x00007eff37aa1740] [error] 1
1
Run Code Online (Sandbox Code Playgroud)