I have successfully built a boost example rotating_file (boost 1.63) using my own cmake file instead of jamfile. Then I have add following modification:
#include <boost/log/sources/global_logger_storage.hpp>
...
//before main
BOOST_LOG_GLOBAL_LOGGER(my_logger, src::logger)
...
//src::logger lg;
src::logger& lg = my_logger::get();
A program also contains this line:
#define BOOST_ALL_DYN_LINK
Here are cmake libs:
target_link_libraries(test "libboost_log.so"
"libboost_log_setup.so"
"libboost_date_time.so"
"libboost_filesystem.so"
"libboost_system.so"
"libboost_thread.so")
This line:
src::logger& lg = my_logger::get();
generates:
global_logger_storage.hpp:154: error: undefined reference to `my_logger::construct_logger()'
What is wrong ?
Edit
I add sink and other attributes this way:
logging::core::get()->add_sink(sink);
logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
logging::core::get()->add_global_attribute("RecordID", attrs::counter< unsigned int >());
so at the end of the BOOST_LOG_GLOBAL_LOGGER_INIT I just add:
src::logger logger;
return logger;
It works.
You need a call to BOOST_LOG_GLOBAL_LOGGER_INIT. In one project I have the following in a header:
// register a global logger
BOOST_LOG_GLOBAL_LOGGER(logger, boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level>)
In the source file I have this:
BOOST_LOG_GLOBAL_LOGGER_INIT(logger, src::severity_logger_mt) {
src::severity_logger_mt<boost::log::trivial::severity_level> logger;
// add attributes
logger.add_attribute("LineID", attrs::counter<unsigned int>(1)); // lines are sequentially numbered
logger.add_attribute("TimeStamp", attrs::local_clock()); // each log line gets a timestamp
return logger;
}
When I comment out the BOOST_LOG_GLOBAL_LOGGER_INIT, I get the same error as you do. My powers of deduction tell me that BOOST_LOG_GLOBAL_LOGGER_INIT provides the definition that you (we) need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With