diff --git a/keywords.txt b/keywords.txt index 34be792..773df52 100644 --- a/keywords.txt +++ b/keywords.txt @@ -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 diff --git a/src/Catena_Log.h b/src/Catena_Log.h index b98e451..549a55e 100644 --- a/src/Catena_Log.h +++ b/src/Catena_Log.h @@ -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 + void cond( + DebugFlags uDebugFlags, + Functor &f + ) + { + if (this->isEnabled(uDebugFlags)) + f(); + } + // fetch current log flags DebugFlags getFlags(void) const {