Public Member Functions | Private Attributes | List of all members
spdlog::details::full_formatter Class Referencefinal

#include <pattern_formatter.h>

Inheritance diagram for spdlog::details::full_formatter:
spdlog::details::flag_formatter

Public Member Functions

 full_formatter (padding_info padinfo)
 
void format (const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) override
 
- Public Member Functions inherited from spdlog::details::flag_formatter
 flag_formatter (padding_info padinfo)
 
 flag_formatter ()=default
 
virtual ~flag_formatter ()=default
 

Private Attributes

std::chrono::seconds cache_timestamp_ {0}
 
fmt::basic_memory_buffer< char, 128 > cached_datetime_
 

Additional Inherited Members

- Protected Attributes inherited from spdlog::details::flag_formatter
padding_info padinfo_
 

Detailed Description

Definition at line 918 of file pattern_formatter.h.

Constructor & Destructor Documentation

spdlog::details::full_formatter::full_formatter ( padding_info  padinfo)
inlineexplicit

Definition at line 921 of file pattern_formatter.h.

922  : flag_formatter(padinfo)
923  {
924  }

Member Function Documentation

void spdlog::details::full_formatter::format ( const details::log_msg msg,
const std::tm &  tm_time,
fmt::memory_buffer dest 
)
inlineoverridevirtual

Implements spdlog::details::flag_formatter.

Definition at line 926 of file pattern_formatter.h.

927  {
928  using std::chrono::duration_cast;
930  using std::chrono::seconds;
931 
932 #ifndef SPDLOG_NO_DATETIME
933 
934  // cache the date/time part for the next second.
935  auto duration = msg.time.time_since_epoch();
936  auto secs = duration_cast<seconds>(duration);
937 
938  if (cache_timestamp_ != secs || cached_datetime_.size() == 0)
939  {
940  cached_datetime_.clear();
941  cached_datetime_.push_back('[');
942  fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_);
943  cached_datetime_.push_back('-');
944 
945  fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_);
946  cached_datetime_.push_back('-');
947 
948  fmt_helper::pad2(tm_time.tm_mday, cached_datetime_);
949  cached_datetime_.push_back(' ');
950 
951  fmt_helper::pad2(tm_time.tm_hour, cached_datetime_);
952  cached_datetime_.push_back(':');
953 
954  fmt_helper::pad2(tm_time.tm_min, cached_datetime_);
955  cached_datetime_.push_back(':');
956 
957  fmt_helper::pad2(tm_time.tm_sec, cached_datetime_);
958  cached_datetime_.push_back('.');
959 
960  cache_timestamp_ = secs;
961  }
963 
964  auto millis = fmt_helper::time_fraction<milliseconds>(msg.time);
965  fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
966  dest.push_back(']');
967  dest.push_back(' ');
968 
969 #else // no datetime needed
970  (void)tm_time;
971 #endif
972 
973 #ifndef SPDLOG_NO_NAME
974  if (!msg.logger_name->empty())
975  {
976  dest.push_back('[');
977  // fmt_helper::append_str(*msg.logger_name, dest);
978  fmt_helper::append_string_view(*msg.logger_name, dest);
979  dest.push_back(']');
980  dest.push_back(' ');
981  }
982 #endif
983 
984  dest.push_back('[');
985  // wrap the level name with color
986  msg.color_range_start = dest.size();
987  // fmt_helper::append_string_view(level::to_c_str(msg.level), dest);
989  msg.color_range_end = dest.size();
990  dest.push_back(']');
991  dest.push_back(' ');
992 
993  // add source location if present
994  if (!msg.source.empty())
995  {
996  dest.push_back('[');
997  fmt_helper::append_string_view(msg.source.filename, dest);
998  dest.push_back(':');
999  fmt_helper::append_int(msg.source.line, dest);
1000  dest.push_back(']');
1001  dest.push_back(' ');
1002  }
1003  // fmt_helper::append_string_view(msg.msg(), dest);
1005  }
void msg(const char *fmt,...)
Definition: message.cpp:107
void append_int(T n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
Definition: fmt_helper.h:40
void pad3(T n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
Definition: fmt_helper.h:90
void append_buf(const fmt::basic_memory_buffer< char, Buffer_Size1 > &buf, fmt::basic_memory_buffer< char, Buffer_Size2 > &dest)
Definition: fmt_helper.h:23
std::chrono::seconds cache_timestamp_
second seconds
Alias for common language habits.
Definition: spacetime.h:83
void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
Definition: fmt_helper.h:30
fmt::basic_memory_buffer< char, 128 > cached_datetime_
string_view_t & to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition: common.h:132
millisecond milliseconds
Alias for common language habits.
Definition: spacetime.h:100
void pad2(int n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
Definition: fmt_helper.h:54

Member Data Documentation

std::chrono::seconds spdlog::details::full_formatter::cache_timestamp_ {0}
private

Definition at line 1008 of file pattern_formatter.h.

fmt::basic_memory_buffer<char, 128> spdlog::details::full_formatter::cached_datetime_
private

Definition at line 1009 of file pattern_formatter.h.


The documentation for this class was generated from the following file: