Question

I'm using Boost.Log library. I've created a named_scope attribute that keeps track of where I am in the code. (I specify it by hand with BOOST_LOG_NAMED_SCOPE("...").) Is it possible to create a filter (using set_filter) that would select only the messages from a particular scope?

Was it helpful?

Solution

Please refer to Andrey's latest & greatest logging doc :

The scope stack is implemented as a thread-specific global storage internally. There is the named_scope attribute that allows hooking this stack into the logging pipeline. This attribute generates value of the nested type named_scope::scope_stack which is the instance of the scope stack. The attribute can be registered in the following way:

logging::core::get()->add_global_attribute("Scope", attrs::named_scope());

Then, you should configure your front end sink filter to latch only your tags of interest (in the filter lambda or in your custom filter which you pass to set_filter() you can use the following in order to extract the scope name, assuming u work with MBCS)

typedef attrs::basic_named_scope< char >::value_type scope_stack;       
logging::value_extractor<char, scope_stack> S("Scope");
scope_stack s = *S(rec);
if ( s.empty() == false )
{
   const attrs::basic_named_scope_entry<char>& e = s.back(); 
   // Filter by e.scope_name
   ...
}

I hope it will work for you :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top