Opened 6 years ago

Closed 6 years ago

#12887 closed Bugs (wontfix)

I had a problem with boost.log when set the filter with & operator

Reported by: 136002018@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.62.0 Severity: Problem
Keywords: Cc:

Description

First I defined keyword:

BOOST_LOG_ATTRIBUTE_KEYWORD(attr_appenders, "Appenders", uint64)

Then I set the filter like this:

void _onSetFilter(SinkTypePtr sink) const {

uint64 mask = 0x01ul << _id; sink->set_filter(attr_appenders & mask);

}

and the error info: /usr/local/include/boost/log/sinks/basic_sink_frontend.hpp:90:18: required from ‘void boost::log::v2_mt_posix::sinks::basic_sink_frontend::set_filter(const FunT&) [with FunT = boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::bitwise_and, boost::proto::argsns_::list2<boost::log::v2_mt_posix::expressions::attribute_actor<long unsigned int, boost::log::v2_mt_posix::fallback_to_none, tag::attr_appenders, boost::phoenix::actor>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<long unsigned int>, 0l> > >, 2l> >]’ /home/yuwenyong/ClionProjects/tinycore/src/tinycore/logging/appender.h:111:47: required from here /usr/local/include/boost/proto/transform/default.hpp:150:9: error:no match for ‘operator&’ (operand types are ‘boost::log::v2_mt_posix::value_ref<long unsigned int, tag::attr_appenders>’ and ‘const long unsigned int’)

BOOST_PROTO_BINARY_DEFAULT_EVAL(&, bitwise_and, make, make)

Change History (4)

comment:1 by anonymous, 6 years ago

Component: Nonelog
Owner: set to Andrey Semashev

comment:2 by Andrey Semashev, 6 years ago

Resolution: wontfix
Status: newclosed

The problem is that the operator is applied to an instance of boost::log::value_ref, which is basically an optional reference to the actual attribute value. operator& cannot be applied to it because the reference can be empty (e.g. if the log record does not contain the attribute), and in this case the operator cannot return any meaningful result.

Currently, your best solution is to write your own filter function that will first test if the attribute value is found and then apply operator&.

bool my_filter(boost::log::value_ref<uint64, tag::attr_appenders> const& appenders)
{
    uint64 mask = 0x01ul << _id;
    if (appenders)
        return (appenders.get() & mask) != 0;
    else
        return false; // the default
}

sink->set_filter(boost::phoenix::bind(&my_filter, attr_appenders.or_none()));

comment:3 by anonymous, 6 years ago

Resolution: wontfix
Status: closedreopened

comment:4 by Andrey Semashev, 6 years ago

Resolution: wontfix
Status: reopenedclosed

I'm not planning to fix it, since the error is the consequence of the library design.

Please, don't reopen, unless you have a suggested way to fix the problem.

Note: See TracTickets for help on using tickets.