3#include "spdlog/fmt/fmt.h"
4#include "spdlog/spdlog.h"
14 const std::string_view what,
15 const std::string_view how)
20 [[nodiscard]] std::string_view
getWhat()
const
24 [[nodiscard]] std::string_view
getHow()
const
38 template<
typename... Args>
40 const std::string_view& fmt_str,
43 std::string user_msg = fmt::format(fmt::runtime(fmt_str),
44 std::forward<Args>(args)...);
46 std::string_view code = errorDef.
getCode();
47 std::string_view what = errorDef.
getWhat();
48 std::string_view how = errorDef.
getHow();
50 return fmt::format(
"[{}] {}\n"
51 " [?] What Went Wrong: {}\n"
52 " [!] How to Fix: {}",
53 code, user_msg, what, how);
68#define LOG_ERROR(code, ...) \
70 if (spdlog::default_logger()->should_log(spdlog::level::err)) { \
71 spdlog::source_loc loc{__FILE__, __LINE__, __FUNCTION__}; \
72 std::string msg = runbook::FormatRunbookLog(code, __VA_ARGS__); \
73 spdlog::default_logger()->log(loc, spdlog::level::err, \
74 spdlog::string_view_t(msg)); \
80#define LOG_CRITICAL(code, ...) \
82 if (spdlog::default_logger()->should_log(spdlog::level::critical)) { \
83 spdlog::source_loc loc{__FILE__, __LINE__, __FUNCTION__}; \
84 std::string msg = runbook::FormatRunbookLog(code, __VA_ARGS__); \
85 spdlog::default_logger()->log(loc, spdlog::level::critical, \
86 spdlog::string_view_t(msg)); \
std::string_view mCode
Definition Runbook.h:30
std::string_view mWhatWentWrongString
Definition Runbook.h:31
consteval ErrorDefinition(const std::string_view code, const std::string_view what, const std::string_view how)
Definition Runbook.h:13
std::string_view getWhat() const
Definition Runbook.h:20
std::string_view mHowToFixString
Definition Runbook.h:32
std::string_view getCode() const
Definition Runbook.h:19
std::string_view getHow() const
Definition Runbook.h:24
static std::string FormatRunbookLog(const ErrorDefinition &errorDef, const std::string_view &fmt_str, Args &&... args)
Internal helper function to format the final log message.
Definition Runbook.h:39