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

@ -115,9 +115,9 @@ using log_clock = std::chrono::system_clock;
using sink_ptr = std::shared_ptr<sinks::sink>;
using sinks_init_list = std::initializer_list<sink_ptr>;
using err_handler = std::function<void(const std::string &err_msg)>;
#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<Args...>;
using wstring_view_t = fmt::basic_string_view<wchar_t>;
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
# 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,14 +342,9 @@ 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<typename T, typename... Args>
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
// 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<typename T, typename... Args>
constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, Args...> fmt) noexcept
{
@ -361,7 +356,13 @@ constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, A
{
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
} // namespace details

View File

@ -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

View File

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