From 8ae7e4d7631e0a2471d2f589ee62de1b81b870e3 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Thu, 9 Mar 2023 14:50:48 +0100 Subject: [PATCH] Added C++ standard check before including . Readded the possibility of using spdlog::info(123). --- include/spdlog/spdlog.h | 140 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 6efab462..720d7a29 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -21,7 +21,7 @@ #include #ifdef __has_include -# if __has_include() +# if __has_include() && __cplusplus >= 202002L # include # define SPDLOG_SOURCE_LOCATION # endif @@ -195,6 +195,42 @@ inline void critical(format_string_t fmt, Args &&... args) { default_logger_raw()->critical(fmt, std::forward(args)...); } + +template +inline void trace(const T &msg) +{ + default_logger_raw()->trace(msg); +} + +template +inline void debug(const T &msg) +{ + default_logger_raw()->debug(msg); +} + +template +inline void info(const T &msg) +{ + default_logger_raw()->info(msg); +} + +template +inline void warn(const T &msg) +{ + default_logger_raw()->warn(msg); +} + +template +inline void error(const T &msg) +{ + default_logger_raw()->error(msg); +} + +template +inline void critical(const T &msg) +{ + default_logger_raw()->critical(msg); +} #endif template @@ -395,6 +431,108 @@ error(wformat_string_t fmt, Args &&... args) -> error; template critical(wformat_string_t fmt, Args &&... args) -> critical; # endif + +template +struct trace +{ + trace(const T &msg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::trace, msg); + } + + trace(format_string_t fmt, T&& arg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::trace, fmt, std::forward(arg)); + } +}; + +template +struct debug +{ + debug(const T &msg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::debug, msg); + } + + debug(format_string_t fmt, T&& arg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::debug, fmt, std::forward(arg)); + } +}; + +template +struct info +{ + info(const T &msg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::info, msg); + } + + info(format_string_t fmt, T&& arg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::info, fmt, std::forward(arg)); + } +}; + +template +struct warn +{ + warn(const T &msg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::warn, msg); + } + + warn(format_string_t fmt, T&& arg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::warn, fmt, std::forward(arg)); + } +}; + +template +struct error +{ + error(const T &msg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::err, msg); + } + + error(format_string_t fmt, T&& arg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::err, fmt, std::forward(arg)); + } +}; + +template +struct critical +{ + critical(const T &msg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::critical, msg); + } + + critical(format_string_t fmt, T&& arg, const std::source_location &loc = std::source_location::current()) + { + default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::critical, fmt, std::forward(arg)); + } +}; + +template +trace(const T &msg) -> trace; + +template +debug(const T &msg) -> debug; + +template +info(const T &msg) -> info; + +template +warn(const T &msg) -> warn; + +template +error(const T &msg) -> error; + +template +critical(const T &msg) -> critical; #endif } // namespace spdlog