61 if (padinfo_.width_ <= wrapped_size)
67 total_pad_ = padinfo.
width_ - wrapped_size;
75 auto half_pad = total_pad_ / 2;
76 auto reminder = total_pad_ & 1;
78 total_pad_ = half_pad + reminder;
96 void pad_it(
size_t count)
99 assert(count <= spaces_.size());
139 if (padinfo_.enabled())
163 if (padinfo_.enabled())
196 static const char *
ampm(
const tm &t)
198 return t.tm_hour >= 12 ?
"PM" :
"AM";
203 return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour;
207 static const char *
days[]{
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"};
225 static const char *
full_days[]{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"};
243 static const char *
months[]{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sept",
"Oct",
"Nov",
"Dec"};
262 "January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
290 const size_t field_size = 24;
322 const size_t field_size = 2;
339 const size_t field_size = 10;
359 const size_t field_size = 4;
376 const size_t field_size = 2;
393 const size_t field_size = 2;
410 const size_t field_size = 2;
425 const size_t field_size = 2;
440 const size_t field_size = 2;
455 const size_t field_size = 2;
470 auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.
time);
471 if (padinfo_.enabled())
473 const size_t field_size = 3;
493 auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.
time);
494 if (padinfo_.enabled())
496 const size_t field_size = 6;
516 auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.
time);
517 if (padinfo_.enabled())
519 const size_t field_size = 9;
539 const size_t field_size = 10;
541 auto duration = msg.
time.time_since_epoch();
542 auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
556 const size_t field_size = 2;
571 const size_t field_size = 11;
593 const size_t field_size = 5;
611 const size_t field_size = 8;
629 const std::chrono::seconds cache_refresh = std::chrono::seconds(5);
637 const size_t field_size = 6;
641 int total_minutes = get_cached_offset(msg, tm_time);
651 total_minutes = -total_minutes;
665 log_clock::time_point last_update_{std::chrono::seconds(0)};
667 int offset_minutes_{0};
669 int get_cached_offset(
const log_msg &msg,
const std::tm &tm_time)
671 if (msg.
time - last_update_ >= cache_refresh)
674 last_update_ = msg.
time;
676 return offset_minutes_;
690 if (padinfo_.enabled())
713 if (padinfo_.enabled())
735 const size_t field_size = 6;
749 if (padinfo_.enabled())
771 const size_t field_size = 1;
840 if (padinfo_.enabled())
886 if (padinfo_.enabled())
928 using std::chrono::duration_cast;
929 using std::chrono::milliseconds;
930 using std::chrono::seconds;
932 #ifndef SPDLOG_NO_DATETIME 935 auto duration = msg.
time.time_since_epoch();
936 auto secs = duration_cast<seconds>(duration);
938 if (cache_timestamp_ != secs || cached_datetime_.size() == 0)
940 cached_datetime_.clear();
941 cached_datetime_.push_back(
'[');
943 cached_datetime_.push_back(
'-');
946 cached_datetime_.push_back(
'-');
949 cached_datetime_.push_back(
' ');
952 cached_datetime_.push_back(
':');
955 cached_datetime_.push_back(
':');
958 cached_datetime_.push_back(
'.');
960 cache_timestamp_ = secs;
964 auto millis = fmt_helper::time_fraction<milliseconds>(msg.
time);
969 #else // no datetime needed 973 #ifndef SPDLOG_NO_NAME 1008 std::chrono::seconds cache_timestamp_{0};
1019 : pattern_(
std::move(pattern))
1020 , eol_(
std::move(eol))
1021 , pattern_time_type_(time_type)
1024 std::memset(&cached_tm_, 0,
sizeof(cached_tm_));
1025 compile_pattern_(pattern_);
1031 , eol_(
std::move(eol))
1032 , pattern_time_type_(time_type)
1035 std::memset(&cached_tm_, 0,
sizeof(cached_tm_));
1042 std::unique_ptr<formatter>
clone()
const override 1044 return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_);
1049 #ifndef SPDLOG_NO_DATETIME 1050 auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.
time.time_since_epoch());
1051 if (secs != last_log_secs_)
1053 cached_tm_ = get_time_(msg);
1054 last_log_secs_ = secs;
1057 for (
auto &f : formatters_)
1059 f->format(msg, cached_tm_, dest);
1066 std::string pattern_;
1070 std::chrono::seconds last_log_secs_;
1072 std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
1089 formatters_.push_back(details::make_unique<details::full_formatter>(padding));
1093 formatters_.push_back(details::make_unique<details::name_formatter>(padding));
1097 formatters_.push_back(details::make_unique<details::level_formatter>(padding));
1101 formatters_.push_back(details::make_unique<details::short_level_formatter>(padding));
1105 formatters_.push_back(details::make_unique<details::t_formatter>(padding));
1109 formatters_.push_back(details::make_unique<details::v_formatter>(padding));
1113 formatters_.push_back(details::make_unique<details::a_formatter>(padding));
1117 formatters_.push_back(details::make_unique<details::A_formatter>(padding));
1122 formatters_.push_back(details::make_unique<details::b_formatter>(padding));
1126 formatters_.push_back(details::make_unique<details::B_formatter>(padding));
1130 formatters_.push_back(details::make_unique<details::c_formatter>(padding));
1134 formatters_.push_back(details::make_unique<details::C_formatter>(padding));
1138 formatters_.push_back(details::make_unique<details::Y_formatter>(padding));
1143 formatters_.push_back(details::make_unique<details::D_formatter>(padding));
1147 formatters_.push_back(details::make_unique<details::m_formatter>(padding));
1151 formatters_.push_back(details::make_unique<details::d_formatter>(padding));
1155 formatters_.push_back(details::make_unique<details::H_formatter>(padding));
1159 formatters_.push_back(details::make_unique<details::I_formatter>(padding));
1163 formatters_.push_back(details::make_unique<details::M_formatter>(padding));
1167 formatters_.push_back(details::make_unique<details::S_formatter>(padding));
1171 formatters_.push_back(details::make_unique<details::e_formatter>(padding));
1175 formatters_.push_back(details::make_unique<details::f_formatter>(padding));
1179 formatters_.push_back(details::make_unique<details::F_formatter>(padding));
1183 formatters_.push_back(details::make_unique<details::E_formatter>(padding));
1187 formatters_.push_back(details::make_unique<details::p_formatter>(padding));
1191 formatters_.push_back(details::make_unique<details::r_formatter>(padding));
1195 formatters_.push_back(details::make_unique<details::R_formatter>(padding));
1200 formatters_.push_back(details::make_unique<details::T_formatter>(padding));
1204 formatters_.push_back(details::make_unique<details::z_formatter>(padding));
1208 formatters_.push_back(details::make_unique<details::pid_formatter>(padding));
1211 #ifdef SPDLOG_ENABLE_MESSAGE_COUNTER 1213 formatters_.push_back(details::make_unique<details::i_formatter>(padding));
1217 formatters_.push_back(details::make_unique<details::color_start_formatter>(padding));
1221 formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding));
1225 formatters_.push_back(details::make_unique<details::source_location_formatter>(padding));
1229 formatters_.push_back(details::make_unique<details::source_filename_formatter>(padding));
1233 formatters_.push_back(details::make_unique<details::source_linenum_formatter>(padding));
1237 formatters_.push_back(details::make_unique<details::source_funcname_formatter>(padding));
1241 formatters_.push_back(details::make_unique<details::ch_formatter>(
'%'));
1245 auto unknown_flag = details::make_unique<details::aggregate_formatter>();
1246 unknown_flag->add_ch(
'%');
1247 unknown_flag->add_ch(flag);
1248 formatters_.push_back((std::move(unknown_flag)));
1260 const size_t max_width = 128;
1282 if (it == end || !std::isdigit(static_cast<unsigned char>(*it)))
1287 auto width =
static_cast<size_t>(*it -
'0');
1288 for (++it; it != end && std::isdigit(static_cast<unsigned char>(*it)); ++it)
1290 auto digit =
static_cast<size_t>(*it -
'0');
1291 width = width * 10 + digit;
1296 void compile_pattern_(
const std::string &pattern)
1298 auto end = pattern.end();
1299 std::unique_ptr<details::aggregate_formatter> user_chars;
1300 formatters_.clear();
1301 for (
auto it = pattern.begin(); it !=
end; ++it)
1307 formatters_.push_back(std::move(user_chars));
1310 auto padding = handle_padspec_(++it, end);
1314 handle_flag_(*it, padding);
1325 user_chars = details::make_unique<details::aggregate_formatter>();
1327 user_chars->add_ch(*it);
1332 formatters_.push_back(std::move(user_chars));
static int to12h(const tm &t)
const std::string * logger_name
scoped_pad(spdlog::string_view_t txt, padding_info &padinfo, fmt::memory_buffer &dest)
std::tm localtime(const std::time_t &time_tt) noexcept
static const char * ampm(const tm &t)
std::tm gmtime(const std::time_t &time_tt) noexcept
void append_int(T n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
void pad3(T n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
void append_buf(const fmt::basic_memory_buffer< char, Buffer_Size1 > &buf, fmt::basic_memory_buffer< char, Buffer_Size2 > &dest)
void pad6(T n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
static const char * months[]
int utc_minutes_offset(const std::tm &tm=details::os::localtime())
scoped_pad(size_t wrapped_size, padding_info &padinfo, fmt::memory_buffer &dest)
const char * to_short_c_str(spdlog::level::level_enum l) noexcept
static const char * days[]
void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
padding_info(size_t width, padding_info::pad_side side)
void pad9(T n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
void push_back(const T &value)
std::basic_string< typename char_t< S >::type > format(const S &format_str, const Args &...args)
constexpr bool empty() const noexcept
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type is_negative(T value)
fmt::string_view string_view_t
string_view_t & to_string_view(spdlog::level::level_enum l) noexcept
static constexpr const char * default_eol
const string_view_t payload
static const char * full_months[]
void pad2(int n, fmt::basic_memory_buffer< char, Buffer_Size > &dest)
unsigned count_digits(T n)
log_clock::time_point time
static const char * full_days[]
auto end(const C &c) -> decltype(c.end())