mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
Small refactoring and support wchar again
This commit is contained in:
parent
23da9f13b0
commit
c2a9bf9974
@ -13,6 +13,11 @@ namespace spdlog {
|
||||
namespace details {
|
||||
namespace fmt_helper {
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline fmt::string_view to_string_view(const fmt::basic_memory_buffer<char, Buffer_Size> &buf) SPDLOG_NOEXCEPT
|
||||
{
|
||||
return fmt::string_view(buf.data(), buf.size());
|
||||
}
|
||||
template<size_t Buffer_Size1, size_t Buffer_Size2>
|
||||
inline void append_buf(const fmt::basic_memory_buffer<char, Buffer_Size1> &buf, fmt::basic_memory_buffer<char, Buffer_Size2> &dest)
|
||||
{
|
||||
|
@ -63,9 +63,10 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Ar
|
||||
|
||||
try
|
||||
{
|
||||
using details::fmt_helper::to_string_view;
|
||||
fmt::memory_buffer buf;
|
||||
fmt::format_to(buf, fmt, args...);
|
||||
details::log_msg log_msg(&name_, lvl, fmt::string_view(buf.data(), buf.size()));
|
||||
details::log_msg log_msg(&name_, lvl, to_string_view(buf));
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
@ -95,9 +96,10 @@ inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
|
||||
}
|
||||
try
|
||||
{
|
||||
using details::fmt_helper::to_string_view;
|
||||
fmt::memory_buffer buf;
|
||||
fmt::format_to(buf, "{}", msg);
|
||||
details::log_msg log_msg(&name_, lvl, fmt::string_view(buf.data(), buf.size()));
|
||||
details::log_msg log_msg(&name_, lvl, to_string_view(buf));
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
@ -209,11 +211,14 @@ inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const
|
||||
try
|
||||
{
|
||||
// format to wmemory_buffer and convert to utf8
|
||||
details::log_msg log_msg(&name_, lvl);
|
||||
using details::fmt_helper::to_string_view;
|
||||
fmt::wmemory_buffer wbuf;
|
||||
fmt::format_to(wbuf, fmt, args...);
|
||||
wbuf_to_utf8buf(wbuf, log_msg.raw);
|
||||
fmt::memory_buffer buf;
|
||||
wbuf_to_utf8buf(wbuf, buf);
|
||||
details::log_msg log_msg(&name_, lvl, to_string_view(buf));
|
||||
sink_it_(log_msg);
|
||||
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
@ -83,7 +83,6 @@ class a_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt_helper::append_string_view(days[tm_time.tm_wday], dest);
|
||||
fmt_helper::append_string_view(days[tm_time.tm_wday], dest);
|
||||
}
|
||||
};
|
||||
@ -94,7 +93,6 @@ class A_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt_helper::append_string_view(full_days[tm_time.tm_wday], dest);
|
||||
fmt_helper::append_string_view(full_days[tm_time.tm_wday], dest);
|
||||
}
|
||||
};
|
||||
@ -105,7 +103,6 @@ class b_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt_helper::append_string_view(months[tm_time.tm_mon], dest);
|
||||
fmt_helper::append_string_view(months[tm_time.tm_mon], dest);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user