Skip to content

Commit 5df84de

Browse files
committed
Merge #12970: logging: bypass timestamp formatting when not logging
339730a logging: bypass timestamp formatting when not logging (Cory Fields) Pull request description: As suggested by @laanwj on IRC: ``` <cfields> whoa <cfields> Leaving test case "knapsack_solver_test"; testing time: 358694ms <cfields> i386 + old wine ^^ <cfields> Leaving test case "knapsack_solver_test"; testing time: 6781ms <cfields> ^^ same, but with the LogPrint commented out ... <wumpus> if both log-to-file and log-to-console is disabled, it should probably bypass all logging ``` Edit: The painful line commented out being the LogPrintf in CWallet::AddToWallet. Tree-SHA512: bc6da67dcdf05e9164fff7a7e9980de897e6f1b0d3f6e1ebde2162cbcba7d54a6ec94283534eb5a1ebde7134533d7fe7e496aa35ea3128c567ed6483eae5212c
2 parents 4ba6da5 + 339730a commit 5df84de

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/util.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ template<typename T, typename... Args> static inline void MarkUsed(const T& t, c
145145
#define LogPrint(category, ...) do { MarkUsed(__VA_ARGS__); } while(0)
146146
#else
147147
#define LogPrintf(...) do { \
148-
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
149-
try { \
150-
_log_msg_ = tfm::format(__VA_ARGS__); \
151-
} catch (tinyformat::format_error &fmterr) { \
152-
/* Original format string will have newline so don't add one here */ \
153-
_log_msg_ = "Error \"" + std::string(fmterr.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
148+
if (fPrintToConsole || fPrintToDebugLog) { \
149+
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
150+
try { \
151+
_log_msg_ = tfm::format(__VA_ARGS__); \
152+
} catch (tinyformat::format_error &fmterr) { \
153+
/* Original format string will have newline so don't add one here */ \
154+
_log_msg_ = "Error \"" + std::string(fmterr.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
155+
} \
156+
LogPrintStr(_log_msg_); \
154157
} \
155-
LogPrintStr(_log_msg_); \
156158
} while(0)
157159

158160
#define LogPrint(category, ...) do { \

0 commit comments

Comments
 (0)