Boost logo

Boost :

From: Boris (boriss_at_[hidden])
Date: 2008-08-20 13:38:18


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk