Changeset View
Changeset View
Standalone View
Standalone View
src/logging.h
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | public: | ||||
fs::path m_file_path; | fs::path m_file_path; | ||||
std::atomic<bool> m_reopen_file{false}; | std::atomic<bool> m_reopen_file{false}; | ||||
~Logger(); | ~Logger(); | ||||
/** Send a string to the log output */ | /** Send a string to the log output */ | ||||
void LogPrintStr(const std::string &str); | 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(); | bool OpenDebugLog(); | ||||
void ShrinkDebugFile(); | void ShrinkDebugFile(); | ||||
uint32_t GetCategoryMask() const { return m_categories.load(); } | uint32_t GetCategoryMask() const { return m_categories.load(); } | ||||
void EnableCategory(LogFlags category); | void EnableCategory(LogFlags category); | ||||
bool EnableCategory(const std::string &str); | bool EnableCategory(const std::string &str); | ||||
void DisableCategory(LogFlags category); | void DisableCategory(LogFlags category); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | #define LogPrintf(...) \ | ||||
} while (0) | } while (0) | ||||
#define LogPrint(category, ...) \ | #define LogPrint(category, ...) \ | ||||
do { \ | do { \ | ||||
MarkUsed(__VA_ARGS__); \ | MarkUsed(__VA_ARGS__); \ | ||||
} while (0) | } while (0) | ||||
#else | #else | ||||
#define LogPrintf(...) \ | #define LogPrintf(...) \ | ||||
do { \ | do { \ | ||||
if (LogInstance().Enabled()) { \ | |||||
/* Unlikely name to avoid shadowing variables */ \ | /* Unlikely name to avoid shadowing variables */ \ | ||||
std::string _log_msg_; \ | std::string _log_msg_; \ | ||||
try { \ | try { \ | ||||
_log_msg_ = tfm::format(__VA_ARGS__); \ | _log_msg_ = tfm::format(__VA_ARGS__); \ | ||||
} catch (tinyformat::format_error & fmterr) { \ | } catch (tinyformat::format_error & fmterr) { \ | ||||
/** \ | /** \ | ||||
* Original format string will have newline so don't add one here \ | * Original format string will have newline so don't add one \ | ||||
* here \ | |||||
*/ \ | */ \ | ||||
_log_msg_ = "Error \"" + std::string(fmterr.what()) + \ | _log_msg_ = "Error \"" + std::string(fmterr.what()) + \ | ||||
"\" while formatting log message: " + \ | "\" while formatting log message: " + \ | ||||
FormatStringFromLogArgs(__VA_ARGS__); \ | FormatStringFromLogArgs(__VA_ARGS__); \ | ||||
} \ | } \ | ||||
LogInstance().LogPrintStr(_log_msg_); \ | LogInstance().LogPrintStr(_log_msg_); \ | ||||
} \ | |||||
} while (0) | } while (0) | ||||
#define LogPrint(category, ...) \ | #define LogPrint(category, ...) \ | ||||
do { \ | do { \ | ||||
if (LogAcceptCategory((category))) { \ | if (LogAcceptCategory((category))) { \ | ||||
LogPrintf(__VA_ARGS__); \ | LogPrintf(__VA_ARGS__); \ | ||||
} \ | } \ | ||||
} while (0) | } while (0) | ||||
#endif | #endif | ||||
Show All 10 Lines |