
Andrey, can you tell me why the following program writes the second message? ---------- #include <boost/log/sources/severity_logger.hpp> #include <boost/log/logging_core.hpp> #include <boost/log/utility/init/to_console.hpp> #include <boost/log/utility/init/to_file.hpp> #include <boost/log/utility/init/common_attributes.hpp> #include <boost/log/formatters/format.hpp> #include <boost/log/formatters/attr.hpp> #include <boost/log/formatters/date_time.hpp> #include <boost/log/formatters/message.hpp> #include <boost/log/filters/attr.hpp> #include <boost/shared_ptr.hpp> enum severity_level { info, warn, error }; boost::log::sources::severity_logger logger; int main() { boost::shared_ptr<boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend>> sink = boost::log::init_log_to_file("test.txt"); boost::log::add_common_attributes(); sink->locked_backend()->set_formatter(boost::log::formatters::format("[%1%] %2%") % boost::log::formatters::attr("Severity") % boost::log::formatters::message()); sink->locked_backend()->auto_flush(true); boost::log::logging_core::get()->set_filter(boost::log::filters::attr<int>("Severity")
info);
BOOST_LOG_SEV(logger, warn) << "first message"; // Message is not written. boost::log::logging_core::get()->set_filter(boost::log::filters::attr<int>("Severity") < warn); BOOST_LOG(logger) << "second message"; // Why is this message written?? } ---------- The first message is not written as the severity level warn is greater than info. However for the second message the default severity level info is smaller than warn. Thus I would expect the second message is not written either? Is this a bug? Boris

Boris wrote:
Andrey,
can you tell me why the following program writes the second message?
----------
[snip]
boost::log::sources::severity_logger logger;
int main() {
[snip]
boost::log::logging_core::get()->set_filter(boost::log::filters::attr<int>("Severity") < warn);
BOOST_LOG(logger) << "second message"; // Why is this message written?? } ----------
The first message is not written as the severity level warn is greater than info. However for the second message the default severity level info is smaller than warn. Thus I would expect the second message is not written either? Is this a bug?
The default severity will be 0, since the logger is default-constructed. And since you set the filter to pass everything with level below warn (which is 1), the second message passes the filter.

On Wed, 20 Aug 2008 19:46:17 +0200, Andrey Semashev <andrey.semashev@gmail.com> wrote:
Boris wrote:
Andrey,
can you tell me why the following program writes the second message?
----------
[snip]
boost::log::sources::severity_logger logger;
int main() {
[snip]
boost::log::logging_core::get()->set_filter(boost::log::filters::attr<int>("Severity") < warn);
BOOST_LOG(logger) << "second message"; // Why is this message written?? } ----------
The first message is not written as the severity level warn is greater than info. However for the second message the default severity level info is smaller than warn. Thus I would expect the second message is not written either? Is this a bug?
The default severity will be 0, since the logger is default-constructed. And since you set the filter to pass everything with level below warn (which is 1), the second message passes the filter.
I see. Then I misunderstood how the filters work. But then again I don't understand why the first message is not written as the severity level is warn (1) and it is greater than info (0)? It should pass the filter? Boris

Boris wrote:
I see. Then I misunderstood how the filters work. But then again I don't understand why the first message is not written as the severity level is warn (1) and it is greater than info (0)? It should pass the filter?
That looks weird. I'll take a closer look on it later.

On Wed, Aug 20, 2008 at 9:58 PM, Boris <boriss@web.de> wrote:
On Wed, 20 Aug 2008 19:46:17 +0200, Andrey Semashev < andrey.semashev@gmail.com> wrote:
I see. Then I misunderstood how the filters work. But then again I don't understand why the first message is not written as the severity level is warn (1) and it is greater than info (0)? It should pass the filter?
Indeed, this was a quite subtle bug. The fix is available in CVS. Thanks for spotting that.
participants (2)
-
Andrey Semashev
-
Boris