I am looking for a portable way to implement lazy evaluation in C ++ for logging. Say I have a simple registration function like
void syslog(int priority, const char *format, ...);
then in the syslog () function we can do:
if (priority < current_priority) return;
therefore, we never call the format function (sprintf). On the other hand, if we use a logging thread like
log << LOG_NOTICE << "test " << 123;
all formatting is always performed, which can take a long time. Is it possible to actually use all the useful properties of ostream (for example, a custom <operator for classes, security type, elegant syntax ...) in such a way that the formation is performed after the level of logging is checked?
c ++ iostream logging lazy-evaluation
Saving
source share