I am using boost 1.54.0. Below you can find a minimum example that illustrates my problem.
I use the severity_logger of boost log. I want to configure my sinks from a stream. (In the following example I use a stringstream. In my real application the stream comes from a file.) I want to use the %Severity% for output or filtering purposes.
My problem is: If I use it as given in the example below, %Severity% is empty.
%LineID% and %Message% are filled as expected. If I set up a sink as given in the outcommented lines, it works as expected.
Any ideas?
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/expressions.hpp>
enum SeverityLevel { trace, fatal };
int main (int argc, char *argv[])
{
boost::log::add_common_attributes();
/*
struct severity_tag;
boost::log::add_console_log(std::clog,
boost::log::keywords::format = (
boost::log::expressions::stream
<< boost::log::expressions::attr< unsigned int >("LineID")
<< ": <" << boost::log::expressions::attr<SeverityLevel, severity_tag >("Severity")
<< "> " << boost::log::expressions::smessage)
); */
std::stringstream s;
s << "[Sinks.MySink]" << std::endl;
s << "Destination=Console" << std::endl;
s << "Format=\"%LineID%: <%Severity%> - %Message%\"" << std::endl;
boost::log::init_from_stream(s);
boost::log::sources::severity_logger<SeverityLevel> lg;
BOOST_LOG_SEV(lg, trace) << "This is a trace message";
BOOST_LOG_SEV(lg, fatal) << "This is a fatal message";
return 0;
}
Sinks.MySink
. Sadly, I have no experience with Boost Log configuration – Narrow