7

I'm trying to get Boost.Log going in my project. The problem comes in the following line from the trivial example:

using namespace boost::log;
core::get()->set_filter
(
    trivial::severity >= trivial::info
);

In my code, this translates to the following:

boost::log::core::get()->set_filter(
  boost::log::trivial::severity >= boost::log::trivial::info
);

However, I get the following errors:

error C2039: 'severity' : is not a member of 'boost::log::v2s_mt_nt5::trivial'
error C2065: 'severity' : undeclared identifier

I'm kind of searching around the namespaces trying to find out how I'm supposed to do this, but I'm not really finding anything that works. It seems it's some crazy lambda function required for this. I'm alright with some alternative (defining a function that fills in the filtering level?), but I'm not sure how to accomplish this. Any ideas?

I'm using Boost.Log version 2.0-r862, and Boost 1.53.0.

SOLUTION: Ryan pointed out that I should check my includes, and sure enough I was only including trivial.hpp, but core.hpp and expressions.hpp are also required as includes. Including them solved the problem.

// need at least these 3 to get "trivial" to work
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
Mark Lakata
  • 19,989
  • 5
  • 106
  • 123
aardvarkk
  • 14,955
  • 7
  • 67
  • 96
  • Hey, aardvark, I'm having trouble filtering the severity. My question is here: stackoverflow.com/q/29707017/1735836 – Patricia Apr 17 '15 at 18:59

2 Answers2

2

Looking at trivial.hpp, it appears severity is part of the keywords namespace. Did you try boost::log::keywords::severity?

Ryan
  • 1,797
  • 12
  • 19
  • Yeah, I've tried that too. Unfortunately I get the following: `error C2784: 'std::_Boolarray std::operator >=(const std::valarray<_Ty> &,const std::valarray<_Ty> &)' : could not deduce template argument for 'const std::valarray<_Ty> &' from 'const boost::parameter::keyword'` – aardvarkk May 01 '13 at 20:04
  • It looks like the >= operator isn't defined for the keyword type? I think the "severity level keyword" is different than a "severity level", so it kind of makes sense that this doesn't work... – aardvarkk May 01 '13 at 20:06
  • 4
    Ugh, this was totally it. For some (stupid?) reason, I assumed I could get away with only including trivial.hpp. Not sure where that logic came from, but the error resolved itself upon including `core.hpp` and `expressions.hpp`. Sorry for my dumbness, and thanks so much for your help! – aardvarkk May 01 '13 at 20:16
  • Not a problem, we all forget the includes sometimes :). Good to hear it worked out. – Ryan May 01 '13 at 20:17
  • @Ryan, I'm having trouble filtering the severity. My question is here: stackoverflow.com/q/29707017/1735836 – Patricia Apr 17 '15 at 19:00
0

Here is a full working example in C++11, that summarizes @aardvarkk solution:

#include <boost/log/expressions.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>

namespace logging = boost::log;

auto init() -> void
{
    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::warning
    );
}

auto main(int argn, char *args[]) -> int
{
    init();

    BOOST_LOG_TRIVIAL(info) << "Testing the log system";
    BOOST_LOG_TRIVIAL(error) << "Testing the log error";


    return 0;
}
Adrian Maire
  • 14,354
  • 9
  • 45
  • 85