Skip to content

Commit 8734c85

Browse files
committed
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 bitcoin#14209. The decision to revert is discussed in bitcoin#16688, which adds verbose logging for validation event notification.
1 parent b499d85 commit 8734c85

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/logging.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ static inline void LogPrintf(const char* fmt, const Args&... args)
155155
}
156156
}
157157

158-
template <typename... Args>
159-
static inline void LogPrint(const BCLog::LogFlags& category, const Args&... args)
160-
{
161-
if (LogAcceptCategory((category))) {
162-
LogPrintf(args...);
163-
}
164-
}
158+
// Use a macro instead of a function for conditional logging to prevent
159+
// evaluating arguments when logging for the category is not enabled.
160+
#define LogPrint(category, ...) \
161+
do { \
162+
if (LogAcceptCategory((category))) { \
163+
LogPrintf(__VA_ARGS__); \
164+
} \
165+
} while (0)
165166

166167
#endif // BITCOIN_LOGGING_H

0 commit comments

Comments
 (0)