From d8ffb37491d717ebf41bad2fe05dd6295c19df57 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Tue, 7 Mar 2023 15:56:47 +0100 Subject: [PATCH] Starting experimenting with std::source_location. --- include/spdlog/spdlog.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 6b7b221a..cc78823a 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -19,6 +19,9 @@ #include #include #include +#if __cplusplus >= 202002L +#include +#endif namespace spdlog { @@ -164,11 +167,25 @@ inline void debug(format_string_t fmt, Args &&... args) default_logger_raw()->debug(fmt, std::forward(args)...); } +#if __cplusplus >= 202002L +template +struct info +{ + info(format_string_t fmt, Args &&...args, 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(args)...); + } +}; + +template +info(format_string_t fmt, Args &&... args) -> info; +#else template inline void info(format_string_t fmt, Args &&... args) { default_logger_raw()->info(fmt, std::forward(args)...); } +#endif template inline void warn(format_string_t fmt, Args &&... args) @@ -262,12 +279,6 @@ 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) {