Reputation: 10171
I have a small project that uses boost::log version 2 (from Boost 1.55). I want to log to a file, so I initialize it like this :
void initializeLogging(boost::log::trivial::severity_level level)
{
logging::add_common_attributes();
logging::add_file_log(
keywords::file_name = "sample.%02N.log",
keywords::open_mode = std::ios::app,
keywords::format = "[%TimeStamp%] %Message%"
);
logging::core::get()->set_filter
(
logging::trivial::severity >= level
);
boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg;
BOOST_LOG_SEV(lg, boost::log::trivial::error) << "INSIDE An error severity message";
}
I see the line INSIDE An error severity message
in the file sample.00.log.
But when I call doStuff
, right after, initializeLogging
nothing is logged.
void doStuff()
{
boost::log::sources::severity_logger< boost::log::trivial::severity_level > lg;
BOOST_LOG_SEV(lg, boost::log::trivial::error) << "An error severity message";
}
This code is in a Windows program, there is no console at can look at. There is nothing in Windows Debug log either.
As you can see, doStuff
has the exact same code as in the first function. Is there something I need to do to make my logging settings permanent?
Upvotes: 0
Views: 351
Reputation: 2470
Is boost::log::sources::severity_logger< boost::log::trivial::severity_level >
a singleton?
You created another local variable lg
for doStuff(), if it's not a singleton, it won't have the initialization.
The initialization:
logging::add_common_attributes();
logging::add_file_log(
keywords::file_name = "sample.%02N.log",
keywords::open_mode = std::ios::app,
keywords::format = "[%TimeStamp%] %Message%"
);
logging::core::get()->set_filter
(
logging::trivial::severity >= level
);
Upvotes: 1