diff options
author | Jeffrey Czyz <jkczyz@gmail.com> | 2019-10-22 10:06:02 -0700 |
---|---|---|
committer | Jeffrey Czyz <jkczyz@gmail.com> | 2019-10-22 13:44:51 -0700 |
commit | 8734c856f85cb506fa97596383dd7e7b9edd7e03 (patch) | |
tree | aa176beeb597fdb711ebca78f3e3a545beb4c9d5 /src/logging.h | |
parent | b499d8576f30d13dfe9000852afe47ee1c28cfbe (diff) |
Replace the LogPrint function with a macro
Calling LogPrint with a category that is not enabled results in
evaluating the remaining function arguments, which may be arbitrarily
complex (and possibly expensive) expressions. Defining LogPrint as a
macro prevents this unnecessary expression evaluation.
This is a partial revert of #14209. The decision to revert is discussed
in #16688, which adds verbose logging for validation event notification.
Diffstat (limited to 'src/logging.h')
-rw-r--r-- | src/logging.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/logging.h b/src/logging.h index 75cd5353c0..e37c0c823b 100644 --- a/src/logging.h +++ b/src/logging.h @@ -155,12 +155,13 @@ static inline void LogPrintf(const char* fmt, const Args&... args) } } -template <typename... Args> -static inline void LogPrint(const BCLog::LogFlags& category, const Args&... args) -{ - if (LogAcceptCategory((category))) { - LogPrintf(args...); - } -} +// Use a macro instead of a function for conditional logging to prevent +// evaluating arguments when logging for the category is not enabled. +#define LogPrint(category, ...) \ + do { \ + if (LogAcceptCategory((category))) { \ + LogPrintf(__VA_ARGS__); \ + } \ + } while (0) #endif // BITCOIN_LOGGING_H |