Commit 1f801828 authored by gabime's avatar gabime

pad6 thread id and micros in formatter

parent 94a7152a
...@@ -86,6 +86,51 @@ inline void pad3(int n, fmt::memory_buffer &dest) ...@@ -86,6 +86,51 @@ inline void pad3(int n, fmt::memory_buffer &dest)
fmt::format_to(dest, "{:03}", n); fmt::format_to(dest, "{:03}", n);
} }
inline void pad6(int n, fmt::memory_buffer &dest)
{
if (n > 99999)
{
append_int(n, dest);
return;
}
if (n > 9999)
{
dest.push_back('0');
}
else if (n > 999)
{
dest.push_back('0');
dest.push_back('0');
}
else if (n > 99)
{
dest.push_back('0');
dest.push_back('0');
dest.push_back('0');
}
else if (n > 9)
{
dest.push_back('0');
dest.push_back('0');
dest.push_back('0');
dest.push_back('0');
}
else if (n >= 0)
{
dest.push_back('0');
dest.push_back('0');
dest.push_back('0');
dest.push_back('0');
dest.push_back('0');
}
else // negatives (unlikely, but just in case let fmt deal with it)
{
fmt::format_to(dest, "{:06}", n);
return;
}
append_int(n, dest);
}
} // namespace fmt_helper } // namespace fmt_helper
} // namespace details } // namespace details
} // namespace spdlog } // namespace spdlog
\ No newline at end of file
...@@ -235,7 +235,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter ...@@ -235,7 +235,7 @@ class f_formatter SPDLOG_FINAL : public flag_formatter
{ {
auto duration = msg.time.time_since_epoch(); auto duration = msg.time.time_since_epoch();
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration).count() % 1000000; auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration).count() % 1000000;
fmt::format_to(dest, "{:06}", static_cast<int>(micros)); fmt_helper::pad6(static_cast<int>(micros), dest);
} }
}; };
...@@ -371,8 +371,8 @@ class t_formatter SPDLOG_FINAL : public flag_formatter ...@@ -371,8 +371,8 @@ class t_formatter SPDLOG_FINAL : public flag_formatter
{ {
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 &, fmt::memory_buffer &dest) override
{ {
// fmt::format_to(dest, "{}", msg.thread_id);
fmt_helper::append_int(msg.thread_id, dest); fmt_helper::pad6(msg.thread_id, dest);
} }
}; };
...@@ -390,7 +390,8 @@ class i_formatter SPDLOG_FINAL : public flag_formatter ...@@ -390,7 +390,8 @@ class i_formatter SPDLOG_FINAL : public flag_formatter
{ {
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 &, fmt::memory_buffer &dest) override
{ {
fmt::format_to(dest, "{:06}", msg.msg_id); // fmt::format_to(dest, "{:06}", msg.msg_id);
fmt_helper::pad6(msg.msg_id, dest);
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment