|
|
@ -120,7 +120,16 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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, fmt::memory_buffer &dest) override
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday); //
|
|
|
|
//fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
|
|
|
|
|
|
|
|
// date
|
|
|
|
|
|
|
|
fmt_helper::append_str(days[tm_time.tm_wday], dest);
|
|
|
|
|
|
|
|
dest.push_back(' ');
|
|
|
|
|
|
|
|
fmt_helper::append_str(months[tm_time.tm_mon], dest);
|
|
|
|
|
|
|
|
dest.push_back(' ');
|
|
|
|
|
|
|
|
fmt_helper::append_int(tm_time.tm_mday, dest);
|
|
|
|
|
|
|
|
dest.push_back(' ');
|
|
|
|
|
|
|
|
// time
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::pad2(tm_time.tm_hour, dest);
|
|
|
|
fmt_helper::pad2(tm_time.tm_hour, dest);
|
|
|
|
dest.push_back(':');
|
|
|
|
dest.push_back(':');
|
|
|
|
fmt_helper::pad2(tm_time.tm_min, dest);
|
|
|
|
fmt_helper::pad2(tm_time.tm_min, dest);
|
|
|
@ -366,7 +375,6 @@ 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_helper::pad6(msg.thread_id, dest);
|
|
|
|
fmt_helper::pad6(msg.thread_id, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -385,7 +393,6 @@ 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_helper::pad6(msg.msg_id, dest);
|
|
|
|
fmt_helper::pad6(msg.msg_id, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -457,39 +464,48 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifndef SPDLOG_NO_DATETIME
|
|
|
|
#ifndef SPDLOG_NO_DATETIME
|
|
|
|
|
|
|
|
|
|
|
|
// each second cache the header
|
|
|
|
// cache the date/time part for the next second.
|
|
|
|
auto duration = msg.time.time_since_epoch();
|
|
|
|
auto duration = msg.time.time_since_epoch();
|
|
|
|
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
|
|
|
|
std::chrono::seconds seconds = std::chrono::duration_cast<std::chrono::seconds>(duration);
|
|
|
|
if (cached_header_.size() == 0 || cached_seconds_ts_ != seconds)
|
|
|
|
|
|
|
|
|
|
|
|
if (cache_timestamp_ != seconds || cached_datetime_.size() == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cached_header_.resize(0);
|
|
|
|
cached_datetime_.resize(0);
|
|
|
|
cached_header_.push_back('[');
|
|
|
|
cached_datetime_.push_back('[');
|
|
|
|
fmt_helper::append_int(tm_time.tm_year + 1900, cached_header_);
|
|
|
|
fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_);
|
|
|
|
cached_header_.push_back('-');
|
|
|
|
cached_datetime_.push_back('-');
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::pad2(tm_time.tm_mon + 1, cached_header_);
|
|
|
|
fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_);
|
|
|
|
cached_header_.push_back('-');
|
|
|
|
cached_datetime_.push_back('-');
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::pad2(tm_time.tm_mday, cached_header_);
|
|
|
|
fmt_helper::pad2(tm_time.tm_mday, cached_datetime_);
|
|
|
|
cached_header_.push_back(' ');
|
|
|
|
cached_datetime_.push_back(' ');
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::pad2(tm_time.tm_hour, cached_header_);
|
|
|
|
fmt_helper::pad2(tm_time.tm_hour, cached_datetime_);
|
|
|
|
cached_header_.push_back(':');
|
|
|
|
cached_datetime_.push_back(':');
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::pad2(tm_time.tm_min, cached_header_);
|
|
|
|
fmt_helper::pad2(tm_time.tm_min, cached_datetime_);
|
|
|
|
cached_header_.push_back(':');
|
|
|
|
cached_datetime_.push_back(':');
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::pad2(tm_time.tm_sec, cached_header_);
|
|
|
|
fmt_helper::pad2(tm_time.tm_sec, cached_datetime_);
|
|
|
|
cached_header_.push_back('.');
|
|
|
|
cached_datetime_.push_back('.');
|
|
|
|
|
|
|
|
|
|
|
|
cached_seconds_ts_ = seconds;
|
|
|
|
cache_timestamp_ = seconds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt_helper::append_buf(cached_header_, dest);
|
|
|
|
fmt_helper::append_buf(cached_datetime_, dest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cache the millis part for the next milli.
|
|
|
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
|
|
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
|
|
|
fmt_helper::pad3(static_cast<int>(millis), dest);
|
|
|
|
if(millis != millis_cache_timestamp_ || cached_millis_.size() == 0)
|
|
|
|
dest.push_back(']');
|
|
|
|
{
|
|
|
|
dest.push_back(' ');
|
|
|
|
cached_millis_.resize(0);
|
|
|
|
|
|
|
|
fmt_helper::pad3(millis, cached_millis_);
|
|
|
|
|
|
|
|
cached_millis_.push_back(']');
|
|
|
|
|
|
|
|
cached_millis_.push_back(' ');
|
|
|
|
|
|
|
|
millis_cache_timestamp_ = millis;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt_helper::append_buf(cached_millis_, dest);
|
|
|
|
#else // no datetime needed
|
|
|
|
#else // no datetime needed
|
|
|
|
(void)tm_time;
|
|
|
|
(void)tm_time;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -512,8 +528,10 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
std::chrono::seconds::rep cached_seconds_ts_{0};
|
|
|
|
std::chrono::seconds cache_timestamp_ {0};
|
|
|
|
fmt::memory_buffer cached_header_;
|
|
|
|
std::chrono::milliseconds::rep millis_cache_timestamp_ {0};
|
|
|
|
|
|
|
|
fmt::basic_memory_buffer<char, 128> cached_datetime_;
|
|
|
|
|
|
|
|
fmt::basic_memory_buffer<char, 8> cached_millis_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace details
|
|
|
|
} // namespace details
|
|
|
|