mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Unified usage of fmt::memory_buffer across the codebase
This commit is contained in:
parent
c2efd6ee58
commit
f5492aed12
@ -44,7 +44,7 @@ SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
|
||||
|
||||
SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
|
||||
{
|
||||
fmt::memory_buffer outbuf;
|
||||
memory_buf_t outbuf;
|
||||
fmt::format_system_error(outbuf, last_errno, msg);
|
||||
msg_ = fmt::to_string(outbuf);
|
||||
}
|
||||
|
@ -105,6 +105,8 @@ using basic_string_view_t = fmt::basic_string_view<T>;
|
||||
|
||||
using string_view_t = basic_string_view_t<char>;
|
||||
|
||||
using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
#ifndef _WIN32
|
||||
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
|
||||
|
@ -66,7 +66,7 @@ SPDLOG_INLINE void file_helper::close()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::write(const fmt::memory_buffer &buf)
|
||||
SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf)
|
||||
{
|
||||
size_t msg_size = buf.size();
|
||||
auto data = buf.data();
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
void reopen(bool truncate);
|
||||
void flush();
|
||||
void close();
|
||||
void write(const fmt::memory_buffer &buf);
|
||||
void write(const memory_buf_t &buf);
|
||||
size_t size() const;
|
||||
const filename_t &filename() const;
|
||||
static bool file_exists(const filename_t &fname);
|
||||
|
@ -12,21 +12,14 @@ namespace spdlog {
|
||||
namespace details {
|
||||
namespace fmt_helper {
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline spdlog::string_view_t to_string_view(const fmt::basic_memory_buffer<char, Buffer_Size> &buf) SPDLOG_NOEXCEPT
|
||||
inline spdlog::string_view_t to_string_view(const memory_buf_t &buf) SPDLOG_NOEXCEPT
|
||||
{
|
||||
return spdlog::string_view_t(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)
|
||||
{
|
||||
auto *buf_ptr = buf.data();
|
||||
dest.append(buf_ptr, buf_ptr + buf.size());
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
|
||||
inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest)
|
||||
{
|
||||
auto *buf_ptr = view.data();
|
||||
if (buf_ptr != nullptr)
|
||||
@ -35,8 +28,8 @@ inline void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buf
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
template<typename T>
|
||||
inline void append_int(T n, memory_buf_t &dest)
|
||||
{
|
||||
fmt::format_int i(n);
|
||||
dest.append(i.data(), i.data() + i.size());
|
||||
@ -49,8 +42,7 @@ inline unsigned count_digits(T n)
|
||||
return static_cast<unsigned>(fmt::internal::count_digits(static_cast<count_type>(n)));
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
inline void pad2(int n, memory_buf_t &dest)
|
||||
{
|
||||
if (n > 99)
|
||||
{
|
||||
@ -72,8 +64,8 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void pad_uint(T n, unsigned int width, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
template<typename T>
|
||||
inline void pad_uint(T n, unsigned int width, memory_buf_t &dest)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>::value, "pad_uint must get unsigned T");
|
||||
auto digits = count_digits(n);
|
||||
@ -85,20 +77,20 @@ inline void pad_uint(T n, unsigned int width, fmt::basic_memory_buffer<char, Buf
|
||||
append_int(n, dest);
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void pad3(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
template<typename T>
|
||||
inline void pad3(T n, memory_buf_t &dest)
|
||||
{
|
||||
pad_uint(n, 3, dest);
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void pad6(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
template<typename T>
|
||||
inline void pad6(T n, memory_buf_t &dest)
|
||||
{
|
||||
pad_uint(n, 6, dest);
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void pad9(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
template<typename T>
|
||||
inline void pad9(T n, memory_buf_t &dest)
|
||||
{
|
||||
pad_uint(n, 9, dest);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace details {
|
||||
|
||||
class log_msg_buffer : public log_msg
|
||||
{
|
||||
fmt::basic_memory_buffer<char, 250> buffer;
|
||||
memory_buf_t buffer;
|
||||
void update_string_views()
|
||||
{
|
||||
logger_name = string_view_t{buffer.data(), logger_name.size()};
|
||||
|
@ -350,7 +350,7 @@ SPDLOG_INLINE void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
wstr_to_utf8buf(filename, buf);
|
||||
return fmt::to_string(buf);
|
||||
}
|
||||
@ -406,7 +406,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
|
||||
}
|
||||
|
||||
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
|
||||
SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, fmt::memory_buffer &target)
|
||||
SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, memory_buf_t &target)
|
||||
{
|
||||
if (wstr.size() > static_cast<size_t>(std::numeric_limits<int>::max()))
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ bool is_color_terminal() SPDLOG_NOEXCEPT;
|
||||
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
|
||||
|
||||
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
|
||||
void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, fmt::memory_buffer &target);
|
||||
void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, memory_buf_t &target);
|
||||
#endif
|
||||
|
||||
} // namespace os
|
||||
|
@ -35,7 +35,7 @@ namespace details {
|
||||
class scoped_padder
|
||||
{
|
||||
public:
|
||||
scoped_padder(size_t wrapped_size, const padding_info &padinfo, fmt::memory_buffer &dest)
|
||||
scoped_padder(size_t wrapped_size, const padding_info &padinfo, memory_buf_t &dest)
|
||||
: padinfo_(padinfo)
|
||||
, dest_(dest)
|
||||
{
|
||||
@ -78,14 +78,14 @@ private:
|
||||
}
|
||||
|
||||
const padding_info &padinfo_;
|
||||
fmt::memory_buffer &dest_;
|
||||
memory_buf_t &dest_;
|
||||
size_t total_pad_;
|
||||
string_view_t spaces_{" ", 64};
|
||||
};
|
||||
|
||||
struct null_scoped_padder
|
||||
{
|
||||
null_scoped_padder(size_t /*wrapped_size*/, const padding_info & /*padinfo*/, fmt::memory_buffer & /*dest*/) {}
|
||||
null_scoped_padder(size_t /*wrapped_size*/, const padding_info & /*padinfo*/, memory_buf_t & /*dest*/) {}
|
||||
};
|
||||
|
||||
template<typename ScopedPadder>
|
||||
@ -96,7 +96,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
ScopedPadder p(msg.logger_name.size(), padinfo_, dest);
|
||||
fmt_helper::append_string_view(msg.logger_name, dest);
|
||||
@ -112,7 +112,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t &level_name = level::to_string_view(msg.level);
|
||||
ScopedPadder p(level_name.size(), padinfo_, dest);
|
||||
@ -129,7 +129,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t level_name{level::to_short_c_str(msg.level)};
|
||||
ScopedPadder p(level_name.size(), padinfo_, dest);
|
||||
@ -162,7 +162,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t field_value{days[static_cast<size_t>(tm_time.tm_wday)]};
|
||||
ScopedPadder p(field_value.size(), padinfo_, dest);
|
||||
@ -181,7 +181,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t field_value{full_days[static_cast<size_t>(tm_time.tm_wday)]};
|
||||
ScopedPadder p(field_value.size(), padinfo_, dest);
|
||||
@ -200,7 +200,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t field_value{months[static_cast<size_t>(tm_time.tm_mon)]};
|
||||
ScopedPadder p(field_value.size(), padinfo_, dest);
|
||||
@ -220,7 +220,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
string_view_t field_value{full_months[static_cast<size_t>(tm_time.tm_mon)]};
|
||||
ScopedPadder p(field_value.size(), padinfo_, dest);
|
||||
@ -237,7 +237,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 24;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -269,7 +269,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -286,7 +286,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 10;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -308,7 +308,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 4;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -325,7 +325,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -342,7 +342,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -359,7 +359,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -376,7 +376,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -393,7 +393,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -410,7 +410,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -427,7 +427,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time);
|
||||
const size_t field_size = 3;
|
||||
@ -445,7 +445,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time);
|
||||
|
||||
@ -464,7 +464,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time);
|
||||
const size_t field_size = 9;
|
||||
@ -482,7 +482,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 10;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -501,7 +501,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 2;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -518,7 +518,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 11;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -542,7 +542,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 5;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -562,7 +562,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 8;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -588,7 +588,7 @@ public:
|
||||
z_formatter(const z_formatter &) = delete;
|
||||
z_formatter &operator=(const z_formatter &) = delete;
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
const size_t field_size = 6;
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -644,7 +644,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
const auto field_size = fmt_helper::count_digits(msg.thread_id);
|
||||
ScopedPadder p(field_size, padinfo_, dest);
|
||||
@ -661,7 +661,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
const auto pid = static_cast<uint32_t>(details::os::pid());
|
||||
auto field_size = fmt_helper::count_digits(pid);
|
||||
@ -678,7 +678,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
ScopedPadder p(msg.payload.size(), padinfo_, dest);
|
||||
fmt_helper::append_string_view(msg.payload, dest);
|
||||
@ -692,7 +692,7 @@ public:
|
||||
: ch_(ch)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
dest.push_back(ch_);
|
||||
}
|
||||
@ -711,7 +711,7 @@ public:
|
||||
{
|
||||
str_ += ch;
|
||||
}
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
fmt_helper::append_string_view(str_, dest);
|
||||
}
|
||||
@ -728,7 +728,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
msg.color_range_start = dest.size();
|
||||
}
|
||||
@ -741,7 +741,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
msg.color_range_end = dest.size();
|
||||
}
|
||||
@ -756,7 +756,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
if (msg.source.empty())
|
||||
{
|
||||
@ -782,7 +782,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
if (msg.source.empty())
|
||||
{
|
||||
@ -808,7 +808,7 @@ public:
|
||||
return rv != nullptr ? rv + 1 : filename;
|
||||
}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
if (msg.source.empty())
|
||||
{
|
||||
@ -829,7 +829,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
if (msg.source.empty())
|
||||
{
|
||||
@ -851,7 +851,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
if (msg.source.empty())
|
||||
{
|
||||
@ -876,7 +876,7 @@ public:
|
||||
, last_message_time_(log_clock::now())
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||
{
|
||||
auto delta = msg.time - last_message_time_;
|
||||
auto delta_units = std::chrono::duration_cast<DurationUnits>(delta);
|
||||
@ -898,7 +898,7 @@ public:
|
||||
: flag_formatter(padinfo)
|
||||
{}
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override
|
||||
{
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::milliseconds;
|
||||
@ -934,7 +934,7 @@ public:
|
||||
|
||||
cache_timestamp_ = secs;
|
||||
}
|
||||
fmt_helper::append_buf(cached_datetime_, dest);
|
||||
dest.append(cached_datetime_.data(), cached_datetime_.data()+cached_datetime_.size());
|
||||
|
||||
auto millis = fmt_helper::time_fraction<milliseconds>(msg.time);
|
||||
fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
|
||||
@ -981,7 +981,7 @@ public:
|
||||
|
||||
private:
|
||||
std::chrono::seconds cache_timestamp_{0};
|
||||
fmt::basic_memory_buffer<char, 128> cached_datetime_;
|
||||
memory_buf_t cached_datetime_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
@ -1012,7 +1012,7 @@ SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, fmt::memory_buffer &dest)
|
||||
SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest)
|
||||
{
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
{}
|
||||
flag_formatter() = default;
|
||||
virtual ~flag_formatter() = default;
|
||||
virtual void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) = 0;
|
||||
virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0;
|
||||
|
||||
protected:
|
||||
padding_info padinfo_;
|
||||
@ -71,7 +71,7 @@ public:
|
||||
pattern_formatter &operator=(const pattern_formatter &other) = delete;
|
||||
|
||||
std::unique_ptr<formatter> clone() const override;
|
||||
void format(const details::log_msg &msg, fmt::memory_buffer &dest) override;
|
||||
void format(const details::log_msg &msg, memory_buf_t &dest) override;
|
||||
|
||||
private:
|
||||
std::string pattern_;
|
||||
|
@ -12,7 +12,7 @@ class formatter
|
||||
{
|
||||
public:
|
||||
virtual ~formatter() = default;
|
||||
virtual void format(const details::log_msg &msg, fmt::memory_buffer &dest) = 0;
|
||||
virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0;
|
||||
virtual std::unique_ptr<formatter> clone() const = 0;
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
SPDLOG_TRY
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, fmt, args...);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
if (level_enabled)
|
||||
@ -243,7 +243,7 @@ public:
|
||||
fmt::wmemory_buffer wbuf;
|
||||
fmt::format_to(wbuf, fmt, args...);
|
||||
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf);
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
|
||||
@ -312,7 +312,7 @@ public:
|
||||
|
||||
try
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
details::os::wstr_to_utf8buf(msg, buf);
|
||||
|
||||
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
|
||||
|
@ -40,7 +40,7 @@ protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
const android_LogPriority priority = convert_to_android_(msg.level);
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
if (use_raw_msg_)
|
||||
{
|
||||
details::fmt_helper::append_string_view(msg.payload, formatted);
|
||||
|
@ -44,7 +44,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg
|
||||
// If color is not supported in the terminal, log as is instead.
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
|
||||
{
|
||||
@ -115,7 +115,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end)
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
|
||||
{
|
||||
fwrite(formatted.data() + start, sizeof(char), end - start, target_file_);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ private:
|
||||
std::unique_ptr<spdlog::formatter> formatter_;
|
||||
std::unordered_map<level::level_enum, string_view_t, level::level_hasher> colors_;
|
||||
void print_ccode_(const string_view_t &color_code);
|
||||
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end);
|
||||
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
|
||||
};
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
|
@ -28,7 +28,7 @@ SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
file_helper_.write(formatted);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ struct daily_filename_calculator
|
||||
{
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::memory_buffer, fmt::wmemory_buffer>::type w;
|
||||
std::conditional<std::is_same<filename_t::value_type, char>::value, memory_buf_t, fmt::wmemory_buffer>::type w;
|
||||
fmt::format_to(
|
||||
w, SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
|
||||
return fmt::to_string(w);
|
||||
@ -78,7 +78,7 @@ protected:
|
||||
file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(time)), truncate_);
|
||||
rotation_tp_ = next_rotation_tp_();
|
||||
}
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
file_helper_.write(formatted);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ protected:
|
||||
// log the "skipped.." message
|
||||
if (skip_counter_ > 0)
|
||||
{
|
||||
fmt::basic_memory_buffer<char, 64> buf;
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, "Skipped {} duplicate messages..", skip_counter_);
|
||||
details::log_msg skipped_msg{msg.logger_name, msg.level, string_view_t{buf.data(), buf.size()}};
|
||||
dist_sink<Mutex>::sink_it_(skipped_msg);
|
||||
|
@ -28,7 +28,7 @@ protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
OutputDebugStringA(fmt::to_string(formatted).c_str());
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
|
||||
if (force_flush_)
|
||||
|
@ -43,7 +43,7 @@ SPDLOG_INLINE rotating_file_sink<Mutex>::rotating_file_sink(
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename, std::size_t index)
|
||||
{
|
||||
typename std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::memory_buffer, fmt::wmemory_buffer>::type w;
|
||||
typename std::conditional<std::is_same<filename_t::value_type, char>::value, memory_buf_t, fmt::wmemory_buffer>::type w;
|
||||
if (index != 0u)
|
||||
{
|
||||
filename_t basename, ext;
|
||||
@ -66,7 +66,7 @@ SPDLOG_INLINE const filename_t &rotating_file_sink<Mutex>::filename() const
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE void rotating_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
current_size_ += formatted.size();
|
||||
if (current_size_ > max_size_)
|
||||
|
@ -26,7 +26,7 @@ template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||
fflush(file_); // flush every line to terminal
|
||||
|
@ -50,7 +50,7 @@ protected:
|
||||
|
||||
if (enable_formatting_)
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
payload = string_view_t(formatted.data(), formatted.size());
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
if (!in_console_)
|
||||
{
|
||||
@ -131,14 +131,14 @@ WORD SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(WORD attri
|
||||
|
||||
// print a range of formatted message to console
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end)
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
|
||||
{
|
||||
auto size = static_cast<DWORD>(end - start);
|
||||
::WriteConsoleA(out_handle_, formatted.data() + start, size, nullptr, nullptr);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const fmt::memory_buffer &formatted)
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
|
||||
{
|
||||
auto size = static_cast<DWORD>(formatted.size());
|
||||
if (size == 0)
|
||||
|
@ -58,10 +58,10 @@ protected:
|
||||
WORD set_foreground_color_(WORD attribs);
|
||||
|
||||
// print a range of formatted message to console
|
||||
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end);
|
||||
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
|
||||
|
||||
// in case we are redirected to file (not in console mode)
|
||||
void write_to_file_(const fmt::memory_buffer &formatted);
|
||||
void write_to_file_(const memory_buf_t &formatted);
|
||||
};
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
|
@ -10,7 +10,7 @@ static const std::string target_filename = "logs/file_helper_test.txt";
|
||||
|
||||
static void write_with_helper(file_helper &helper, size_t howmany)
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
spdlog::memory_buf_t formatted;
|
||||
fmt::format_to(formatted, "{}", std::string(howmany, '1'));
|
||||
helper.write(formatted);
|
||||
helper.flush();
|
||||
|
@ -2,30 +2,32 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
void test_pad2(int n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad2(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad3(uint32_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad3(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad6(std::size_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad6(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
||||
void test_pad9(std::size_t n, const char *expected)
|
||||
{
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
spdlog::details::fmt_helper::pad9(n, buf);
|
||||
REQUIRE(fmt::to_string(buf) == expected);
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "includes.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
|
||||
// log to str and return it
|
||||
template<typename... Args>
|
||||
|
||||
static std::string log_to_str(const std::string &msg, const Args &... args)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
@ -61,9 +62,9 @@ TEST_CASE("color range test1", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
|
||||
fmt::memory_buffer buf;
|
||||
memory_buf_t buf;
|
||||
fmt::format_to(buf, "Hello");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size()));
|
||||
formatter->format(msg, formatted);
|
||||
@ -77,7 +78,7 @@ TEST_CASE("color range test2", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 0);
|
||||
@ -89,7 +90,7 @@ TEST_CASE("color range test3", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^***%$");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 3);
|
||||
@ -101,7 +102,7 @@ TEST_CASE("color range test4", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
@ -113,7 +114,7 @@ TEST_CASE("color range test5", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%^");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 0);
|
||||
@ -124,7 +125,7 @@ TEST_CASE("color range test6", "[pattern_formatter]")
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("**%$");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 2);
|
||||
@ -198,8 +199,8 @@ TEST_CASE("clone-default-formatter", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
@ -213,8 +214,8 @@ TEST_CASE("clone-default-formatter2", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
@ -228,8 +229,8 @@ TEST_CASE("clone-formatter", "[pattern_formatter]")
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2));
|
||||
@ -243,8 +244,8 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]")
|
||||
std::string logger_name = "test2";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
|
||||
fmt::memory_buffer formatted_1;
|
||||
fmt::memory_buffer formatted_2;
|
||||
memory_buf_t formatted_1;
|
||||
memory_buf_t formatted_2;
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
REQUIRE(fmt::to_string(formatted_1) == fmt::to_string(formatted_2));
|
||||
@ -263,7 +264,7 @@ static const char *test_path = "/a/b//myfile.cpp";
|
||||
TEST_CASE("short filename formatter-1", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{test_path, 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
@ -274,7 +275,7 @@ TEST_CASE("short filename formatter-1", "[pattern_formatter]")
|
||||
TEST_CASE("short filename formatter-2", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s:%#", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{"myfile.cpp", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
@ -285,7 +286,7 @@ TEST_CASE("short filename formatter-2", "[pattern_formatter]")
|
||||
TEST_CASE("short filename formatter-3", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%s %v", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{"", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
@ -296,7 +297,7 @@ TEST_CASE("short filename formatter-3", "[pattern_formatter]")
|
||||
TEST_CASE("full filename formatter", "[pattern_formatter]")
|
||||
{
|
||||
spdlog::pattern_formatter formatter("%g", spdlog::pattern_time_type::local, "");
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "logger-name";
|
||||
spdlog::source_loc source_loc{test_path, 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, "logger-name", spdlog::level::info, "Hello");
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
// save the line without the eol
|
||||
auto eol_len = strlen(details::os::default_eol);
|
||||
|
Loading…
Reference in New Issue
Block a user