Boost logo

Boost :

Subject: Re: [boost] boost log: attributes and different loggers
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2010-06-10 11:42:34

On 06/10/2010 02:19 PM, Dirk Griffioen wrote:
> Hi,
> I am trying to use 2 loggers
> - 1 severity logger
> - 1 'normal' logger
> However, when I add
> sink->set_filter(flt::attr< severity_level >("Severity") >= level);
> to the severity logger sink and try to use the second logger I get:
> terminate called after throwing an instance of
> 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::log_mt_posix::missing_value>
> >'
> what(): Requested attribute value not found
> The second logger has no formatter:
> backend->set_formatter(fmt::stream << fmt::message());
> Nor has it any attribute.
> I tried different solutions, but nothing works - what am I missing?

If you emit log records from the basic logger (not the one with severity
level), the record doesn't contain the severity level attached. The
filter throws because it doesn't find it in the record.

You can change the filter in two ways to avoid the exception:

1. flt::attr< severity_level >("Severity", std::nothrow) >= level

That way the filter will silently drop all records without the level

2. !flt::has_attr< severity_level >("Severity") ||
    flt::attr< severity_level >("Severity") >= level

That way it will pass all records without the level.

Boost list run by bdawes at, gregod at, cpdaniel at, john at