File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -62,14 +62,24 @@ bool LogAcceptCategory(const char* category);
6262/* * Send a string to the log output */
6363int LogPrintStr (const std::string& str);
6464
65- #define LogPrint (category, ...) do { \
66- if (LogAcceptCategory ((category))) { \
67- LogPrintStr (tfm::format (__VA_ARGS__)); \
68- } \
65+ /* * Get format string from VA_ARGS for error reporting */
66+ template <typename ... Args> std::string FormatStringFromLogArgs (const char *fmt, const Args&... args) { return fmt; }
67+
68+ #define LogPrintf (...) do { \
69+ std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
70+ try { \
71+ _log_msg_ = tfm::format (__VA_ARGS__); \
72+ } catch (std::runtime_error &e) { \
73+ /* Original format string will have newline so don't add one here */ \
74+ _log_msg_ = " Error \" " + std::string (e.what ()) + " \" while formatting log message: " + FormatStringFromLogArgs (__VA_ARGS__); \
75+ } \
76+ LogPrintStr (_log_msg_); \
6977} while (0 )
7078
71- #define LogPrintf (...) do { \
72- LogPrintStr (tfm::format (__VA_ARGS__)); \
79+ #define LogPrint (category, ...) do { \
80+ if (LogAcceptCategory ((category))) { \
81+ LogPrintf (__VA_ARGS__); \
82+ } \
7383} while (0 )
7484
7585template <typename ... Args>
You can’t perform that action at this time.
0 commit comments