I wanted to make the Scope attribute configurable from settings. The snippet below is the code I had to write to have this pretty basic feature working. And still I couldn't add an extra flag for printing only the file name. Is it intended to be this hard or am I missing something:
// This is used to convert a run-time map of named scope format flags to// the compile-time boost parameter pack, and then create a Boost.Log scope formatter // from it.structmake_name_scope_actor_t{typedefblog::formatter_factory<char>::args_mapargs_map_t;mutableboost::optional<format_named_scope_actor>_actor;args_map_tconst&_args;mutableargs_map_t::const_iterator_curr;make_name_scope_actor_t(args_map_tconst&args_):_args(args_),_curr(_args.begin()){next(blog::aux::empty_arg_list());}operatorformat_named_scope_actor()const{BOOST_ASSERT(_actor);return*_actor;}template<typename_Keywords>voidfinalize(_Keywordsconst&kwords_)const{_actor=blog::expressions::aux::format_named_scope<char,boost::phoenix::actor>("Scope",blog::fallback_to_none(),add(kwords_,blog::keywords::format="%n (%f:%l)"));}voidfinalize(blog::aux::empty_arg_listconst&kwords_)const{finalize(blog::keywords::format="%n (%f:%l)");}template<typename_Keywords,typename_Keyword>statictypenameboost::enable_if<mpl::contains<_Keywords,typename_Keyword::key_type>,_Keywords>::typeadd(_Keywordsconst&kwords_,_Keywordconst&){returnkwords_;}template<typename_Keywords,typename_Keyword>statictypenameboost::disable_if<mpl::contains<_Keywords,typename_Keyword::key_type>,boost::parameter::aux::arg_list<_Keyword,_Keywords>>::typeadd(_Keywordsconst&kwords_,_Keywordconst&kword_){return(kwords_,kword_);}template<typename_Keyword>staticboost::parameter::aux::arg_list<_Keyword,blog::aux::empty_arg_list>add(blog::aux::empty_arg_listroot_,_Keywordconst&kword_){returnboost::parameter::aux::arg_list<_Keyword,blog::aux::empty_arg_list>(kword_,root_);}template<typename_Keywords>voidnext(_Keywordsconst&kwords_)const{usingnamespaceblog;if(_curr==_args.end())finalize(kwords_);else{if(_curr->first==keywords::tag::format::keyword_name())next(add(kwords_,keywords::format=_curr++->second));elseif(_curr->first==keywords::tag::delimiter::keyword_name())next(add(kwords_,keywords::delimiter=_curr++->second));elseif(_curr->first==keywords::tag::depth::keyword_name())next(add(kwords_,keywords::depth=boost::lexical_cast<size_t>(_curr++->second)));elseif(_curr->first==keywords::tag::iteration::keyword_name())next(add(kwords_,keywords::iteration=(_curr++->second=="reverse"?blog::expressions::reverse:blog::expressions::forward)));elseif(_curr->first==keywords::tag::MinSeverity::keyword_name())++_curr,next(kwords_);// ignoreelseLOG_THROW(std::invalid_argument,"Unknown keyword "<<_curr->first<<" in Scope log config")}}};format_named_scope_actormake_name_scope_actor(std::map<std::string,std::string>const&args_){returnmake_name_scope_actor_t(args_);}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Also, I didn't understand the problem with the filename flag. You allow to set the scope list element format, it can just contain %f to display the filename only.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure why would you try to compose parameter pack like that
Because my way is more correct since I don't have to duplicate the defaults and worry about them changing in the next release. But whichever way you do it, this code is boilerplate and, arguably, should live in the library and not in the user code.
Also, I didn't understand the problem with the filename flag. You allow to set the scope list element format, it can just contain %f to display the filename only.
How? The final parsing of the format string is done inside the library and I could find an easy way to add an extra flag.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I see. Please, create a ticket and I'll try to implement it in future versions. In the meantime you can implement your own formatter that suits your needs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will, thanks. It would be nice though if there were an easier way to get this done than filing a ticket. The way the formatter is done right now I'd have to reimplement the entire thing with a lot of copy/paste to get that flag added.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wanted to make the Scope attribute configurable from settings. The snippet below is the code I had to write to have this pretty basic feature working. And still I couldn't add an extra flag for printing only the file name. Is it intended to be this hard or am I missing something:
I'm not sure why would you try to compose parameter pack like that. It could be simpler, really:
Also, I didn't understand the problem with the filename flag. You allow to set the scope list element format, it can just contain %f to display the filename only.
Oh, end is args.end().
Because my way is more correct since I don't have to duplicate the defaults and worry about them changing in the next release. But whichever way you do it, this code is boilerplate and, arguably, should live in the library and not in the user code.
How? The final parsing of the format string is done inside the library and I could find an easy way to add an extra flag.
Ok, have it your way.
Maybe.
What flag? I don't understand.
I'd like to add a flag, say %s, that works like %f but prints only the file name not the entire path.
I see. Please, create a ticket and I'll try to implement it in future versions. In the meantime you can implement your own formatter that suits your needs.
I will, thanks. It would be nice though if there were an easier way to get this done than filing a ticket. The way the formatter is done right now I'd have to reimplement the entire thing with a lot of copy/paste to get that flag added.