From d8ffb37491d717ebf41bad2fe05dd6295c19df57 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Tue, 7 Mar 2023 15:56:47 +0100 Subject: [PATCH 1/7] 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) { From 74d3a59688a5ee73d10bec249b2eef96a58a8376 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Wed, 8 Mar 2023 12:23:49 +0100 Subject: [PATCH 2/7] Managing WCHAR=ON case. --- include/spdlog/spdlog.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index cc78823a..e25d4338 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -175,16 +175,36 @@ struct info { default_logger_raw()->log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, level::info, fmt, std::forward(args)...); } + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + info(wformat_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)...); + } +# endif }; template info(format_string_t fmt, Args &&... args) -> info; + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +template +info(wformat_string_t fmt, Args &&... args) -> info; +# endif #else template inline void info(format_string_t fmt, Args &&... args) { default_logger_raw()->info(fmt, std::forward(args)...); } + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +template +inline void info(wformat_string_t fmt, Args &&... args) +{ + default_logger_raw()->info(fmt, std::forward(args)...); +} +# endif #endif template @@ -242,12 +262,6 @@ inline void debug(wformat_string_t fmt, Args &&... args) default_logger_raw()->debug(fmt, std::forward(args)...); } -template -inline void info(wformat_string_t fmt, Args &&... args) -{ - default_logger_raw()->info(fmt, std::forward(args)...); -} - template inline void warn(wformat_string_t fmt, Args &&... args) { From d5f4d79e1a73d3edc48d06574907f18cc57ec15a Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Thu, 9 Mar 2023 13:38:50 +0100 Subject: [PATCH 3/7] Include source_location only after checking if source_location exists in the std library used. Implementation extended to all logging levels. --- include/spdlog/spdlog.h | 200 ++++++++++++++++++++++++++++------------ tests/test_misc.cpp | 4 +- 2 files changed, 145 insertions(+), 59 deletions(-) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index e25d4338..6efab462 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -19,8 +19,12 @@ #include #include #include -#if __cplusplus >= 202002L -#include + +#ifdef __has_include +# if __has_include() +# include +# define SPDLOG_SOURCE_LOCATION +# endif #endif namespace spdlog { @@ -155,6 +159,7 @@ inline void log(level::level_enum lvl, format_string_t fmt, Args &&... default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); } +#ifndef SPDLOG_SOURCE_LOCATION template inline void trace(format_string_t fmt, Args &&... args) { @@ -167,46 +172,12 @@ 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)...); - } - -# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - info(wformat_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)...); - } -# endif -}; - -template -info(format_string_t fmt, Args &&... args) -> info; - -# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -template -info(wformat_string_t fmt, Args &&... args) -> info; -# endif -#else template inline void info(format_string_t fmt, Args &&... args) { default_logger_raw()->info(fmt, std::forward(args)...); } -# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -template -inline void info(wformat_string_t fmt, Args &&... args) -{ - default_logger_raw()->info(fmt, std::forward(args)...); -} -# endif -#endif - template inline void warn(format_string_t fmt, Args &&... args) { @@ -224,6 +195,7 @@ inline void critical(format_string_t fmt, Args &&... args) { default_logger_raw()->critical(fmt, std::forward(args)...); } +#endif template inline void log(source_loc source, level::level_enum lvl, const T &msg) @@ -237,7 +209,8 @@ inline void log(level::level_enum lvl, const T &msg) default_logger_raw()->log(lvl, msg); } -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +#ifndef SPDLOG_SOURCE_LOCATION +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT template inline void log(source_loc source, level::level_enum lvl, wformat_string_t fmt, Args &&... args) { @@ -262,6 +235,12 @@ inline void debug(wformat_string_t fmt, Args &&... args) default_logger_raw()->debug(fmt, std::forward(args)...); } +template +inline void info(wformat_string_t fmt, Args &&... args) +{ + default_logger_raw()->info(fmt, std::forward(args)...); +} + template inline void warn(wformat_string_t fmt, Args &&... args) { @@ -279,37 +258,144 @@ inline void critical(wformat_string_t fmt, Args &&... args) { default_logger_raw()->critical(fmt, std::forward(args)...); } +# endif #endif -template -inline void trace(const T &msg) +#ifdef SPDLOG_SOURCE_LOCATION +template +struct trace { - default_logger_raw()->trace(msg); -} + trace(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::trace, fmt, std::forward(args)...); + } -template -inline void debug(const T &msg) +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + trace(wformat_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::trace, fmt, std::forward(args)...); + } +# endif +}; + +template +struct debug { - default_logger_raw()->debug(msg); -} + debug(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::debug, fmt, std::forward(args)...); + } -template -inline void warn(const T &msg) +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + debug(wformat_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::debug, fmt, std::forward(args)...); + } +# endif +}; + +template +struct info { - default_logger_raw()->warn(msg); -} + 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 -inline void error(const T &msg) +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + info(wformat_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)...); + } +# endif +}; + +template +struct warn { - default_logger_raw()->error(msg); -} + warn(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::warn, fmt, std::forward(args)...); + } -template -inline void critical(const T &msg) +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + warn(wformat_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::warn, fmt, std::forward(args)...); + } +# endif +}; + +template +struct error { - default_logger_raw()->critical(msg); -} + error(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::err, fmt, std::forward(args)...); + } + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + error(wformat_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::err, fmt, std::forward(args)...); + } +# endif +}; + +template +struct critical +{ + critical(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::critical, fmt, std::forward(args)...); + } + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + critical(wformat_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::critical, fmt, std::forward(args)...); + } +# endif +}; + +template +trace(format_string_t fmt, Args &&... args) -> trace; + +template +debug(format_string_t fmt, Args &&... args) -> debug; + +template +info(format_string_t fmt, Args &&... args) -> info; + +template +warn(format_string_t fmt, Args &&... args) -> warn; + +template +error(format_string_t fmt, Args &&... args) -> error; + +template +critical(format_string_t fmt, Args &&... args) -> critical; + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +template +trace(wformat_string_t fmt, Args &&... args) -> trace; + +template +debug(wformat_string_t fmt, Args &&... args) -> debug; + +template +info(wformat_string_t fmt, Args &&... args) -> info; + +template +warn(wformat_string_t fmt, Args &&... args) -> warn; + +template +error(wformat_string_t fmt, Args &&... args) -> error; + +template +critical(wformat_string_t fmt, Args &&... args) -> critical; +# endif +#endif } // namespace spdlog diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index b6807154..6c51cd3d 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -255,11 +255,11 @@ TEST_CASE("default logger API", "[default logger]") REQUIRE(oss.str() == "*** Hello again 2" + std::string(spdlog::details::os::default_eol)); oss.str(""); - spdlog::error(123); + spdlog::error("{}", 123); REQUIRE(oss.str() == "*** 123" + std::string(spdlog::details::os::default_eol)); oss.str(""); - spdlog::critical(std::string("some string")); + spdlog::critical("some string"); REQUIRE(oss.str() == "*** some string" + std::string(spdlog::details::os::default_eol)); oss.str(""); From 940057927fb230e93c7575846f980a73ccf5e4af Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Thu, 9 Mar 2023 14:48:55 +0100 Subject: [PATCH 4/7] Reverting tests. --- tests/test_misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index 6c51cd3d..b6807154 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -255,11 +255,11 @@ TEST_CASE("default logger API", "[default logger]") REQUIRE(oss.str() == "*** Hello again 2" + std::string(spdlog::details::os::default_eol)); oss.str(""); - spdlog::error("{}", 123); + spdlog::error(123); REQUIRE(oss.str() == "*** 123" + std::string(spdlog::details::os::default_eol)); oss.str(""); - spdlog::critical("some string"); + spdlog::critical(std::string("some string")); REQUIRE(oss.str() == "*** some string" + std::string(spdlog::details::os::default_eol)); oss.str(""); From 8ae7e4d7631e0a2471d2f589ee62de1b81b870e3 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Thu, 9 Mar 2023 14:50:48 +0100 Subject: [PATCH 5/7] 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 From e950911a4a95a08423cdf732489ba4cb60fdf617 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Fri, 10 Mar 2023 14:41:27 +0100 Subject: [PATCH 6/7] Added tests for log functions. --- tests/test_misc.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_misc.cpp b/tests/test_misc.cpp index b6807154..6a6b474a 100644 --- a/tests/test_misc.cpp +++ b/tests/test_misc.cpp @@ -258,6 +258,18 @@ TEST_CASE("default logger API", "[default logger]") spdlog::error(123); REQUIRE(oss.str() == "*** 123" + std::string(spdlog::details::os::default_eol)); + oss.str(""); + spdlog::log(spdlog::level::err, 123); + REQUIRE(oss.str() == "*** 123" + std::string(spdlog::details::os::default_eol)); + + oss.str(""); + spdlog::log(spdlog::level::err, "{}", 123); + REQUIRE(oss.str() == "*** 123" + std::string(spdlog::details::os::default_eol)); + + oss.str(""); + spdlog::log(spdlog::level::err, "{}{}{}", 1, 2, 3); + REQUIRE(oss.str() == "*** 123" + std::string(spdlog::details::os::default_eol)); + oss.str(""); spdlog::critical(std::string("some string")); REQUIRE(oss.str() == "*** some string" + std::string(spdlog::details::os::default_eol)); From aa6f732844e8996f0384c6a0dd71da134d76cea0 Mon Sep 17 00:00:00 2001 From: Gianluca Martino Date: Fri, 10 Mar 2023 14:48:02 +0100 Subject: [PATCH 7/7] Added support also for spdlog::log functions. Added overloading for std::source_location in logger class. --- include/spdlog/logger.h | 31 +++++++++++++++ include/spdlog/spdlog.h | 84 ++++++++++++++++++++++++++++++----------- 2 files changed, 93 insertions(+), 22 deletions(-) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 1fafdabd..f321ad5d 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -27,6 +27,13 @@ #include +#ifdef __has_include +# if __has_include() && __cplusplus >= 202002L +# include +# define SPDLOG_SOURCE_LOCATION +# endif +#endif + #ifndef SPDLOG_NO_EXCEPTIONS # define SPDLOG_LOGGER_CATCH(location) \ catch (const std::exception &ex) \ @@ -90,6 +97,14 @@ public: log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); } +#ifdef SPDLOG_SOURCE_LOCATION + template + void log(std::source_location loc, level::level_enum lvl, format_string_t fmt, Args &&... args) + { + log_(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, lvl, details::to_string_view(fmt), std::forward(args)...); + } +#endif + template void log(level::level_enum lvl, format_string_t fmt, Args &&... args) { @@ -109,6 +124,14 @@ public: log(loc, lvl, "{}", msg); } +#ifdef SPDLOG_SOURCE_LOCATION + template + void log(std::source_location loc, level::level_enum lvl, const T &msg) + { + log(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, lvl, msg); + } +#endif + void log(log_clock::time_point log_time, source_loc loc, level::level_enum lvl, string_view_t msg) { bool log_enabled = should_log(lvl); @@ -183,6 +206,14 @@ public: log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); } +# ifdef SPDLOG_SOURCE_LOCATION + template + void log(std::source_location loc, level::level_enum lvl, wformat_string_t fmt, Args &&... args) + { + log_(spdlog::source_loc{loc.file_name(), static_cast(loc.line()), loc.function_name()}, lvl, details::to_string_view(fmt), std::forward(args)...); + } +# endif + template void log(level::level_enum lvl, wformat_string_t fmt, Args &&... args) { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 720d7a29..7e3532c3 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -20,13 +20,6 @@ #include #include -#ifdef __has_include -# if __has_include() && __cplusplus >= 202002L -# include -# define SPDLOG_SOURCE_LOCATION -# endif -#endif - namespace spdlog { using default_factory = synchronous_factory; @@ -147,6 +140,7 @@ SPDLOG_API void set_default_logger(std::shared_ptr default_logge // spdlog::apply_logger_env_levels(mylogger); SPDLOG_API void apply_logger_env_levels(std::shared_ptr logger); +#ifndef SPDLOG_SOURCE_LOCATION template inline void log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&... args) { @@ -159,7 +153,6 @@ inline void log(level::level_enum lvl, format_string_t fmt, Args &&... default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); } -#ifndef SPDLOG_SOURCE_LOCATION template inline void trace(format_string_t fmt, Args &&... args) { @@ -196,6 +189,18 @@ inline void critical(format_string_t fmt, Args &&... args) default_logger_raw()->critical(fmt, std::forward(args)...); } +template +inline void log(source_loc source, level::level_enum lvl, const T &msg) +{ + default_logger_raw()->log(source, lvl, msg); +} + +template +inline void log(level::level_enum lvl, const T &msg) +{ + default_logger_raw()->log(lvl, msg); +} + template inline void trace(const T &msg) { @@ -231,21 +236,7 @@ inline void critical(const T &msg) { default_logger_raw()->critical(msg); } -#endif - -template -inline void log(source_loc source, level::level_enum lvl, const T &msg) -{ - default_logger_raw()->log(source, lvl, msg); -} -template -inline void log(level::level_enum lvl, const T &msg) -{ - default_logger_raw()->log(lvl, msg); -} - -#ifndef SPDLOG_SOURCE_LOCATION # ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT template inline void log(source_loc source, level::level_enum lvl, wformat_string_t fmt, Args &&... args) @@ -298,6 +289,27 @@ inline void critical(wformat_string_t fmt, Args &&... args) #endif #ifdef SPDLOG_SOURCE_LOCATION +template +struct log +{ + log(level::level_enum lvl, 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()}, lvl, fmt, std::forward(args)...); + } + + log(source_loc source, level::level_enum lvl, format_string_t fmt, Args &&... args) + { + default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); + } + +# ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + log(level::level_enum lvl, wformat_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()}, lvl, fmt, std::forward(args)...); + } +# endif +}; + template struct trace { @@ -394,6 +406,9 @@ struct critical # endif }; +template +log(level::level_enum lvl, format_string_t fmt, Args &&... args) -> log; + template trace(format_string_t fmt, Args &&... args) -> trace; @@ -413,6 +428,9 @@ template critical(format_string_t fmt, Args &&... args) -> critical; # ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT +template +log(level::level_enum lvl, wformat_string_t fmt, Args &&... args) -> log; + template trace(wformat_string_t fmt, Args &&... args) -> trace; @@ -432,6 +450,25 @@ template critical(wformat_string_t fmt, Args &&... args) -> critical; # endif +template +struct log +{ + log(source_loc source, level::level_enum lvl, const T &msg) + { + default_logger_raw()->log(source, lvl, msg); + } + + log(level::level_enum lvl, 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()}, lvl, msg); + } + + log(level::level_enum lvl, 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()}, lvl, fmt, std::forward(arg)); + } +}; + template struct trace { @@ -516,6 +553,9 @@ struct critical } }; +template +log(level::level_enum lvl, const T &msg) -> log; + template trace(const T &msg) -> trace;