mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 00:40:26 +08:00
Fixed issue #908
This commit is contained in:
parent
3bfcb0468e
commit
7068c45115
@ -43,20 +43,6 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void append_uint(T n, unsigned int width, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>::value, "append_uint must get unsigned T");
|
||||
auto digits = fmt::internal::count_digits(n);
|
||||
if(width > digits)
|
||||
{
|
||||
const char* zeroes = "0000000000000000000";
|
||||
dest.append(zeroes, zeroes + width-digits);
|
||||
}
|
||||
append_int(n, dest);
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
@ -80,23 +66,38 @@ 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)
|
||||
{
|
||||
static_assert(std::is_unsigned<T>::value, "append_uint must get unsigned T");
|
||||
auto digits = fmt::internal::count_digits(n);
|
||||
if(width > digits)
|
||||
{
|
||||
const char* zeroes = "0000000000000000000";
|
||||
dest.append(zeroes, zeroes + width-digits);
|
||||
}
|
||||
append_int(n, dest);
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void pad3(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
append_uint(n, 3, 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)
|
||||
{
|
||||
append_uint(n, 6, 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)
|
||||
{
|
||||
append_uint(n, 9, dest);
|
||||
pad_uint(n, 9, dest);
|
||||
}
|
||||
|
||||
|
||||
|
@ -653,9 +653,9 @@ public:
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
const size_t field_size = 6;
|
||||
const size_t field_size = fmt::internal::count_digits(msg.thread_id);
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
fmt_helper::pad6(msg.thread_id, dest);
|
||||
fmt_helper::append_int(msg.thread_id, dest);
|
||||
}
|
||||
};
|
||||
|
||||
@ -668,9 +668,10 @@ public:
|
||||
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
const size_t field_size = 6;
|
||||
const auto pid = static_cast<uint32_t>(details::os::pid());
|
||||
const size_t field_size = fmt::internal::count_digits(pid);
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
fmt_helper::pad6(static_cast<size_t>(details::os::pid()), dest);
|
||||
fmt_helper::append_int(pid, dest);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user