nestlog: + trailing args with .end_scope()
This commit is contained in:
parent
605f4df41f
commit
7c964ab93c
3 changed files with 16 additions and 15 deletions
|
|
@ -14,7 +14,8 @@ fib(int n) {
|
|||
retval = fib(n - 1) + fib(n - 2);
|
||||
log(":n ", n);
|
||||
}
|
||||
log("<- :retval ", retval);
|
||||
|
||||
log.end_scope("<- :retval ", retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ namespace xo {
|
|||
/* common implementation for .preamble(), .postamble() */
|
||||
void entryexit_aux(std::string_view name1,
|
||||
std::string_view name2,
|
||||
char label_char,
|
||||
bool newline_flag);
|
||||
char label_char);
|
||||
|
||||
private:
|
||||
/* current nesting level for this thread */
|
||||
|
|
@ -110,8 +109,7 @@ namespace xo {
|
|||
void
|
||||
state_impl<CharT, Traits>::entryexit_aux(std::string_view name1,
|
||||
std::string_view name2,
|
||||
char label_char,
|
||||
bool newline_flag)
|
||||
char label_char)
|
||||
{
|
||||
log_streambuf_type * sbuf = this->p_sbuf_phase1_.get();
|
||||
|
||||
|
|
@ -123,9 +121,6 @@ namespace xo {
|
|||
|
||||
/* scope name */
|
||||
this->ss_ << name1 << name2;
|
||||
|
||||
if (newline_flag)
|
||||
this->ss_ << "\n";
|
||||
} /*entryexit_aux*/
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
|
|
@ -133,7 +128,7 @@ namespace xo {
|
|||
state_impl<CharT, Traits>::preamble(std::string_view name1,
|
||||
std::string_view name2)
|
||||
{
|
||||
this->entryexit_aux(name1, name2, '+' /*label_char*/, false /*!newline_flag*/);
|
||||
this->entryexit_aux(name1, name2, '+' /*label_char*/);
|
||||
} /*preamble*/
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
|
|
@ -141,7 +136,7 @@ namespace xo {
|
|||
state_impl<CharT, Traits>::postamble(std::string_view name1,
|
||||
std::string_view name2)
|
||||
{
|
||||
this->entryexit_aux(name1, name2, '-' /*label_char*/, true /*newline_flag*/);
|
||||
this->entryexit_aux(name1, name2, '-' /*label_char*/);
|
||||
} /*postamble*/
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ namespace xo {
|
|||
state_impl_type * logstate = require_indent_thread_local_state();
|
||||
|
||||
/* log to per-thread stream to prevent data races */
|
||||
tosn(logstate2stream(logstate), rest...);
|
||||
tosn(logstate2stream(logstate), std::forward<Tn>(rest)...);
|
||||
|
||||
this->flush2sbuf(logstate);
|
||||
}
|
||||
|
|
@ -114,10 +114,11 @@ namespace xo {
|
|||
} /*log*/
|
||||
|
||||
template<typename... Tn>
|
||||
bool operator()(Tn&&... rest) { return this->log(rest...); }
|
||||
bool operator()(Tn&&... args) { return this->log(std::forward<Tn>(args)...); }
|
||||
|
||||
/* call once to end scope before dtor */
|
||||
void end_scope();
|
||||
template<typename... Tn>
|
||||
void end_scope(Tn&&... args);
|
||||
|
||||
private:
|
||||
/* establish stream for logging; use thread-local storage for threadsafetỵ
|
||||
|
|
@ -162,7 +163,7 @@ namespace xo {
|
|||
|
||||
logstate->preamble(this->name1_, this->name2_);
|
||||
|
||||
tosn(logstate2stream(logstate), " ", args...);
|
||||
tosn(logstate2stream(logstate), " ", std::forward<Tn>(args)...);
|
||||
|
||||
logstate->flush2sbuf(std::clog.rdbuf());
|
||||
|
||||
|
|
@ -227,8 +228,9 @@ namespace xo {
|
|||
} /*flush2sbuf*/
|
||||
|
||||
template <typename CharT, typename Traits>
|
||||
template <typename... Tn>
|
||||
void
|
||||
basic_scope<CharT, Traits>::end_scope()
|
||||
basic_scope<CharT, Traits>::end_scope(Tn&&... args)
|
||||
{
|
||||
if(!this->finalized_) {
|
||||
this->finalized_ = true;
|
||||
|
|
@ -239,6 +241,9 @@ namespace xo {
|
|||
logstate->decr_nesting();
|
||||
|
||||
logstate->postamble(this->name1_, this->name2_);
|
||||
|
||||
tosn(logstate2stream(logstate), " ", std::forward<Tn>(args)...);
|
||||
|
||||
logstate->flush2sbuf(std::clog.rdbuf());
|
||||
}
|
||||
} /*end_scope*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue