Skip to content

Commit

Permalink
Fix #164: add gLog.cond(flags, functor)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Apr 21, 2019
1 parent 43b2da6 commit d372e8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ cStreamLineCollector KEYWORD1
cTotalizer KEYWORD1
clock_seq_hi_and_reserved KEYWORD2
clock_seq_low KEYWORD2
cond KEYWORD2
configure KEYWORD2
create KEYWORD2
dataOffset KEYWORD2
Expand Down
17 changes: 17 additions & 0 deletions src/Catena_Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ class cLog
) __attribute__((__format__(__printf__, 3, 4)));
/* format counts start with 2 for non-static C++ member fns */

// log, using debug flags and a template; you can write:
// gLog.cond(gLog.kTrace,
// [&](){gCatena.SafePrintf("message", arg1, arg2); })
// and the debug code will only be called if trace is enabled.
// But it may be nicer to write:
// if (gLog.isEnabled(gLog.kTrace))
// gCatena.SafePrintf("message", arg1, arg2...);
template <typename Functor>
void cond(
DebugFlags uDebugFlags,
Functor &f
)
{
if (this->isEnabled(uDebugFlags))
f();
}

// fetch current log flags
DebugFlags getFlags(void) const
{
Expand Down

0 comments on commit d372e8f

Please sign in to comment.