[英]How to use loggers of boost.log?
Try basic boost.log example but failed 尝试基本的boost.log示例但失败了
I am integrating Boost.log v2 into my project. 我正在将Boost.log v2集成到我的项目中。 The platform is windows 10 with vs2017.
该平台是带有vs2017的Windows 10。 The program is compiled target x64.
该程序编译为目标x64。
#include <boost/thread/mutex.hpp>
#include <boost/core/null_deleter.hpp>
#include <boost/log/common.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/exceptions.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sinks.hpp>
void test(){
boost::log::sources::severity_logger<severity_level> slg1;
slg1.open_record(); // this is ok
slg1.open_record(normal); // this line failed at next code
}
template< typename BaseT, typename LevelT = int >
class basic_severity_logger : public BaseT
{
template< typename ArgsT >
record open_record_unlocked(ArgsT const& args)
{
// !!! error at here !!!
// because "normal" is an enum variable that doesn't support "operator[]"
m_SeverityAttr.set_value(args[keywords::severity | m_DefaultSeverity]);
return base_type::open_record_unlocked(args);
}
};
Actually, I don't know how basic_severity_logger
is called ? 实际上,我不知道如何调用
basic_severity_logger
?
// logger with multithread supported
boost::log::sources::severity_logger_mt<severity_level> slg;
slg.open_record(); // failed with "no member named 'open_record' in severity_logger_mt<...>"
slg.open_record(DEBUG); // failed with "no member named 'open_record' in severity_logger_mt<...>"
Currently, the code failed at compling step, not reaching linking stage yet. 目前,代码在编译步骤失败,尚未到达链接阶段。
I have tried boost-1.64, boost-1.68 and boost-1.70, the problem remains the same 我尝试过boost-1.64,boost-1.68和boost-1.70,问题依然存在
Could anyone help me ? 谁能帮助我?
error mesage for first part of code 第一部分代码的错误消息
D:\libraries\boost\boost_1_70_0\boost/log/sources/severity_feature.hpp(252): error C2676: binary “[”:“const ArgsT”does not define this operator or a conversion to a type acceptable to the predefined operator
with
[
ArgsT=severity_level
]
Thank you all, guys. 谢谢你们,伙计们。 I know how to solve it now, but I don't know why yet.
我现在知道如何解决它,但我不知道为什么。
modify code like follows: 修改代码如下:
boost::log::sources::severity_logger<boost::log::trivial::severity_level> slg1;
slg1.open_record();
BOOST_LOG_SEV(slg1, boost::log::trivial::trace) << "A regular message";
slg1.open_record(boost::log::keywords::severity=boost::log::trivial::trace);
boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> slg;
slg.open_record();
slg.open_record(boost::log::keywords::severity=boost::log::trivial::trace);
The key is that used parameter boost::log::keywords::severity
关键是使用参数
boost::log::keywords::severity
slg1.open_record(boost::log::keywords::severity=boost::log::trivial::trace);
Does anyone tell me how does it work? 有谁告诉我它是如何工作的? Is
boost::log::keywords::severity
a functional object or something else ? boost::log::keywords::severity
是一个功能对象还是其他东西?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.