0

Try basic boost.log example but failed

I am integrating Boost.log v2 into my project. The platform is windows 10 with vs2017. The program is compiled target 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 ?

// 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

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
        ]
Laine
  • 179
  • 1
  • 8

1 Answers1

0

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 parameterboost::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 ?

Laine
  • 179
  • 1
  • 8
  • `boost::log::keywords::severity` is a Boost.Parameter (https://www.boost.org/doc/libs/1_70_0/libs/parameter/doc/html/index.html) keyword. – Andrey Semashev May 15 '19 at 14:42