From 8488b027e99403df12479ac80aea1fef381cd4b4 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 16 Sep 2023 19:50:23 +0300 Subject: [PATCH] Formatting --- example/example.cpp | 2 +- include/spdlog/common.h | 27 ++++++++++++++------------- include/spdlog/logger.h | 4 ---- tests/test_source_location.cpp | 1 - 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index c2b5cd51..bf27fa02 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -29,7 +29,7 @@ void replace_default_logger_example(); // Uncomment to enable source location support. // This will add filename/line/column info to the log (and in to the resulting binary so take care). -// #define SPDLOG_EMIT_SOURCE_LOCATION +// #define SPDLOG_EMIT_SOURCE_LOCATION #include "spdlog/spdlog.h" #include "spdlog/cfg/env.h" // support for loading levels from the environment variable diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 53b001a1..eabd2873 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -18,7 +18,7 @@ #include #if __has_include() -#include +# include #endif #if __cpp_lib_source_location >= 201907 @@ -115,9 +115,9 @@ using log_clock = std::chrono::system_clock; using sink_ptr = std::shared_ptr; using sinks_init_list = std::initializer_list; using err_handler = std::function; + #ifdef SPDLOG_USE_STD_FORMAT namespace fmt_lib = std; - using string_view_t = std::string_view; using memory_buf_t = std::string; using wstring_view_t = std::wstring_view; @@ -141,7 +141,7 @@ using format_string_t = fmt::format_string; using wstring_view_t = fmt::basic_string_view; using wmemory_buf_t = fmt::basic_memory_buffer; # define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) -#endif +#endif // SPDLOG_USE_STD_FORMAT #if defined(SPDLOG_NO_ATOMIC_LEVELS) using level_t = details::null_atomic_int; @@ -342,26 +342,27 @@ constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noex } #endif -// convert format_string<...> to string_view depending on std::format or {fmt} versions -#ifndef SPDLOG_USE_STD_FORMAT -template -constexpr inline fmt::basic_string_view to_string_view(fmt::basic_format_string fmt) noexcept -{ - return fmt; -} -#elif __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L +// convert format_string<...> to string_view depending on format lib versions +#if defined(SPDLOG_USE_STD_FORMAT) +# if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L template constexpr std::basic_string_view to_string_view(std::basic_format_string fmt) noexcept { return fmt.get(); } -#else // std::format and __cpp_lib_format < 202207L +# else // std::format and __cpp_lib_format < 202207L template constexpr std::basic_string_view to_string_view(std::basic_format_string fmt) noexcept { return fmt; } - +# endif +#else // {fmt} version +template +constexpr inline fmt::basic_string_view to_string_view(fmt::basic_format_string fmt) noexcept +{ + return fmt; +} #endif } // namespace details diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index ec4cd029..b4a70824 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -173,19 +173,16 @@ public: log(loc, level::trace, msg); } - void debug(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); } - void info(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); } - void warn(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::warn, msg); @@ -364,7 +361,6 @@ protected: void err_handler_(const std::string &msg); }; - } // namespace spdlog #ifdef SPDLOG_HEADER_ONLY diff --git a/tests/test_source_location.cpp b/tests/test_source_location.cpp index e22f2dcc..391d039c 100644 --- a/tests/test_source_location.cpp +++ b/tests/test_source_location.cpp @@ -18,4 +18,3 @@ TEST_CASE("test_source_location", "[source_location]") } #endif -