Boost logo

Boost Users :

Subject: [Boost-users] Boost::Log named_scope issue
From: Kieran Parsons (kp.0987_at_[hidden])
Date: 2010-10-27 08:37:44


Can someone give me a working example of using named_scope for
Boost::Log? I have tried something like:

 boost::shared_ptr< boost::log::core > logCore = boost::log::core::get();
 logCore->add_global_attribute("Scope", boost::make_shared<
boost::log::attributes::named_scope >());

 boost::shared_ptr<
  boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend >
> sink = boost::log::init_log_to_file("myfile.txt");

  sink->locked_backend()->set_formatter
  (
   boost::log::formatters::stream
   << boost::log::formatters::named_scope(
                       "Scope",
                       keywords::iteration = boost::log::formatters::reverse,
                       keywords::delimiter = " | ")
   );
  logCore->add_sink(sink);

  BOOST_LOG_FUNCTION();
  BOOST_LOG_NAMED_SCOPE("MyScope");
  boost::log::sources::logger lg;
  BOOST_LOG(lg) << "TEST";

But it fails with an exception during the BOOST_LOG (I think due to
missing attribute).

As a general comment, the fact that none of the tutorial examples in
the documentation work as-is makes it extremely difficult for a newbie
to use (namespaces undefined, lack of include files etc).

Thanks for your help.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net