Formatting

This commit is contained in:
gabime 2023-09-16 19:50:23 +03:00
parent ad18d4e1cb
commit 8488b027e9
4 changed files with 15 additions and 19 deletions

View File

@ -18,7 +18,7 @@
#include <cstdint> #include <cstdint>
#if __has_include(<version>) #if __has_include(<version>)
#include <version> # include <version>
#endif #endif
#if __cpp_lib_source_location >= 201907 #if __cpp_lib_source_location >= 201907
@ -115,9 +115,9 @@ using log_clock = std::chrono::system_clock;
using sink_ptr = std::shared_ptr<sinks::sink>; using sink_ptr = std::shared_ptr<sinks::sink>;
using sinks_init_list = std::initializer_list<sink_ptr>; using sinks_init_list = std::initializer_list<sink_ptr>;
using err_handler = std::function<void(const std::string &err_msg)>; using err_handler = std::function<void(const std::string &err_msg)>;
#ifdef SPDLOG_USE_STD_FORMAT #ifdef SPDLOG_USE_STD_FORMAT
namespace fmt_lib = std; namespace fmt_lib = std;
using string_view_t = std::string_view; using string_view_t = std::string_view;
using memory_buf_t = std::string; using memory_buf_t = std::string;
using wstring_view_t = std::wstring_view; using wstring_view_t = std::wstring_view;
@ -141,7 +141,7 @@ using format_string_t = fmt::format_string<Args...>;
using wstring_view_t = fmt::basic_string_view<wchar_t>; using wstring_view_t = fmt::basic_string_view<wchar_t>;
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>; using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
# define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) # define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x)
#endif #endif // SPDLOG_USE_STD_FORMAT
#if defined(SPDLOG_NO_ATOMIC_LEVELS) #if defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_int; 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 #endif
// convert format_string<...> to string_view depending on std::format or {fmt} versions // convert format_string<...> to string_view depending on format lib versions
#ifndef SPDLOG_USE_STD_FORMAT #if defined(SPDLOG_USE_STD_FORMAT)
template<typename T, typename... Args> # if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
constexpr inline fmt::basic_string_view<T> to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept
{
return fmt;
}
#elif __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
template<typename T, typename... Args> template<typename T, typename... Args>
constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept
{ {
return fmt.get(); return fmt.get();
} }
#else // std::format and __cpp_lib_format < 202207L # else // std::format and __cpp_lib_format < 202207L
template<typename T, typename... Args> template<typename T, typename... Args>
constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept
{ {
return fmt; return fmt;
} }
# endif
#else // {fmt} version
template<typename T, typename... Args>
constexpr inline fmt::basic_string_view<T> to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept
{
return fmt;
}
#endif #endif
} // namespace details } // namespace details

View File

@ -173,19 +173,16 @@ public:
log(loc, level::trace, msg); log(loc, level::trace, msg);
} }
void debug(string_view_t msg, source_loc loc = source_loc::current()) void debug(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::debug, msg); log(loc, level::debug, msg);
} }
void info(string_view_t msg, source_loc loc = source_loc::current()) void info(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::info, msg); log(loc, level::info, msg);
} }
void warn(string_view_t msg, source_loc loc = source_loc::current()) void warn(string_view_t msg, source_loc loc = source_loc::current())
{ {
log(loc, level::warn, msg); log(loc, level::warn, msg);
@ -364,7 +361,6 @@ protected:
void err_handler_(const std::string &msg); void err_handler_(const std::string &msg);
}; };
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY

View File

@ -18,4 +18,3 @@ TEST_CASE("test_source_location", "[source_location]")
} }
#endif #endif