Hi guys,
I want to define a global logger that can be used in other place.
The severity level always be "info".
I init the log like this:
#include <cstdlib>
#include
#include
#include
#include
#include
#include
// Here we define our application severity levels.
enum severity_level
{
normal,
notification,
warning,
error,
critical
};
// The formatting logic for the severity level
template< typename CharT, typename TraitsT >
inline std::basic_ostream< CharT, TraitsT >& operator<<
(std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
{
static const char* const str[] =
{
"normal",
"notification",
"warning",
"error",
"critical"
};
if (static_caststd::size_t(lvl) < (sizeof(str) / sizeof(*str)))
strm << str[lvl];
else
strm << static_cast<int>(lvl);
return strm;
}
// Global logger declaration
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(test_lg,
boost::log::sources::severity_logger_mt)
void try_logging()
{
boost::log::sources::severity_logger_mt& lg =
test_lg::get();
// TODO:
// always write "info" record, Unknown reason!
BOOST_LOG_SEV(lg, normal) << "This is a normal severity record";
BOOST_LOG_SEV(lg, notification) << "This is a notification severity
record";
BOOST_LOG_SEV(lg, warning) << "This is a warning severity record";
BOOST_LOG_SEV(lg, error) << "This is a error severity record";
BOOST_LOG_SEV(lg, critical) << "This is a critical severity record";
}
int main(int argc, char* argv[])
{
try_logging();
return EXIT_SUCCESS;
}
In the log i got this:
[2015-01-14 19:00:34.800935] [0x40000300] [info] This is a normal
severity re
cord
[2015-01-14 19:00:34.805935] [0x40000300] [info] This is a notification
sever
ity record
[2015-01-14 19:00:34.806935] [0x40000300] [info] This is a warning
severity r
ecord
[2015-01-14 19:00:34.806935] [0x40000300] [info] This is a error
severity rec
ord
[2015-01-14 19:00:34.806935] [0x40000300] [info] This is a critical
severity
record
What do i miss?
Thank you!
Bill