I'm using boost log (v1.71) to try and write logs. Our architecture involves a set of dynamically loaded shared objects, and I'm having trouble using the named scope attribute in the shared objects.
I am setting up a global logger in one of our support util libraries, which has logger.hh and logger.cxx:
//logger.hh
#include <boost/log/trivial.hpp>
// etc.
BOOST_LOG_GLOBAL_LOGGER(my_logger, src::severity_logger_mt<trivial::severity_level>)
#define LOG_TRACE BOOST_LOG_SEV(my_logger::get(), trace)
// etc...
and
//logger.cxx
BOOST_LOG_GLOBAL_LOGGER_INIT(my_logger, src::severity_logger_mt<trivial::severity_level>)
{
src::severity_logger_mt<trivial::severity_level> lg;
lg.add_attribute("Scope", boost::log::attributes::named_scope());
return lg;
}
These get built into a shared library, linked at compile time to the main application and the dynamically loaded plugins. In the main application I'm initialising the logger:
//main.cxx
#include "logger.hh"
int main()
{
logging::formatter fmt = expr::stream
<< expr::format_named_scope("Scope", keywords::format = "%n") << " - " << expr::message;
logging::add_console_log(std::clog, keywords::format = fmt);
BOOST_LOG_NAMED_SCOPE("main");
LOG_WARNING << "test log";
// Main code continues, including dynamically loading plugin shared objects.
}
Finally in the shared object plugin, linked to the util library:
//plugin.cxx
void Activity()
{
BOOST_LOG_NAMED_SCOPE("Activity");
LOG_WARNING << "activity log";
}
I have heavily paraphrased a lot of this, but hopefully all the key ingredients are here. Currently the output for running the program looks like:
main - test log
- activity log
Can anyone help me understand what I need to do to get the named scopes working? I appreciate that the use case here is unusual, but I would prefer to keep the single global logger shared between the whole program.
Using gcc 4.8.3, on RHEL7.
Aucun commentaire:
Enregistrer un commentaire