diff --git a/src/logging.h b/src/logging.h --- a/src/logging.h +++ b/src/logging.h @@ -90,6 +90,9 @@ /** Send a string to the log output */ void LogPrintStr(const std::string &str); + /** Returns whether logs will be written to any output */ + bool Enabled() const { return m_print_to_console || m_print_to_file; } + bool OpenDebugLog(); void ShrinkDebugFile(); @@ -152,19 +155,22 @@ #else #define LogPrintf(...) \ do { \ - /* Unlikely name to avoid shadowing variables */ \ - std::string _log_msg_; \ - try { \ - _log_msg_ = tfm::format(__VA_ARGS__); \ - } catch (tinyformat::format_error & fmterr) { \ - /** \ - * Original format string will have newline so don't add one here \ - */ \ - _log_msg_ = "Error \"" + std::string(fmterr.what()) + \ - "\" while formatting log message: " + \ - FormatStringFromLogArgs(__VA_ARGS__); \ + if (LogInstance().Enabled()) { \ + /* Unlikely name to avoid shadowing variables */ \ + std::string _log_msg_; \ + try { \ + _log_msg_ = tfm::format(__VA_ARGS__); \ + } catch (tinyformat::format_error & fmterr) { \ + /** \ + * Original format string will have newline so don't add one \ + * here \ + */ \ + _log_msg_ = "Error \"" + std::string(fmterr.what()) + \ + "\" while formatting log message: " + \ + FormatStringFromLogArgs(__VA_ARGS__); \ + } \ + LogInstance().LogPrintStr(_log_msg_); \ } \ - LogInstance().LogPrintStr(_log_msg_); \ } while (0) #define LogPrint(category, ...) \ do { \