Boost logo

Boost Users :

Subject: [Boost-users] [LOG]: set_filter error in tutorial_filtering.cpp and per-sink instance filtering
From: Johan Lundberg (lundberj_at_[hidden])
Date: 2013-10-16 10:11:55


Dear all,
(this is my first post to this list)

I'm trying to make a boost log sink that would filter on a severity level
which should be
thread-safely modifiable while logging is ongoing.

On my way there I get errors while trying to compile this tutorial example:

http://www.boost.org/doc/libs/1_54_0/libs/log/example/doc/tutorial_filtering.cpp

The file as-is compiles and runs fine, but if I switch on the user-provided
filtering
function example by activating the block in #if 0 (and commenting out the
other
definition of init()) I get errors related to phoenix bind:

The offending line is 155:

    sink->set_filter(phoenix::bind(&my_filter, severity, tag_attr));

I would be grateful for advice on how to get that working. More details on
that at the end of the mail.

Now, assuming I get past the errors, what is a good way to add a per-sink
log level filter? I may have
several instances of the sink. To clarify: I know this is not the right
syntax, but If I could use a custom
functor or a C++11 lambda for a filter I would do something like this:

using ATseverity=std::atomic<severity_level> ; // (severity is an enum)

shared_ptr<ATseverity> shared_log_level = std::make_shared<ATseverity>(warning);

sink->set_filter(
  [=shared_log_level]->bool(severity_level const& level, std::string
const& tag){
    return level >= shared_log_level->get();
  });

I could then store and modify the shared_log_level from elsewhere.

Is there a right way to do this?

    cheers /Johan

          Details on the compilation error: I think this is the relevant
part of the error message:

/myboost154/include/boost/phoenix/core/preprocessed/expression_10.hpp:140:17:
error: could not convert
‘boost::proto::make_expr<boost::phoenix::detail::tag::function_eval,
boost::proto::domainns_::basic_default_domain,
boost::phoenix::detail::function_ptr<2, bool, bool (*)(const
boost::log::v2_mt_posix::value_ref<severity_level>&, const
boost::log::v2_mt_posix::value_ref<std::basic_string<char> >&)>,
boost::log::v2_mt_posix::expressions::attribute_keyword<tag::severity>,
boost::log::v2_mt_posix::expressions::attribute_keyword<tag::tag_attr>
>((* & a0), (* & a1), (* & a2))’
from
‘const type {aka const
boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval,
boost::proto::argsns_::list3<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::phoenix::detail::function_ptr<2,bool,
bool (*)(const
boost::log::v2_mt_posix::value_ref<severity_level>&,
const boost::log::v2_mt_posix::value_ref<std::basic_string<char>>&)> >, 0l>,
boost::log::v2_mt_posix::expressions::attribute_keyword<tag::severity>,
boost::log::v2_mt_posix::expressions::attribute_keyword<tag::tag_attr> >, 3l>}’
to
‘boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::phoenix::detail::function_ptr<2,
bool, bool (*)(const boost::log::v2_mt_posix::value_ref<severity_level>&,
const boost::log::v2_mt_posix::value_ref<std::basic_string<char> >&)>
>, 0l>::proto_child0 {
aka
boost::phoenix::detail::function_ptr<2, bool,
bool (*)(const boost::log::v2_mt_posix::value_ref<severity_level>&,
const boost::log::v2_mt_posix::value_ref<std::basic_string<char>
>&)>}’ };

I tried boost 1.54 and compiled with gcc 4.7.1 and 4.8.1 under Linux,
with and without C++11 mode:

g++ -std=gnu++11 -DBOOST_ALL_DYN_LINK boostlogexample.cpp -L
$BOOST/lib/ -I $BOOST/include/ -pthread -lboost_system
-lboost_log_setup -lboost_log \
-lboost_date_time -lboost_thread -lrt -lboost_filesystem



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net