Agora  1.2.0
Agora project
pattern_formatter-inl.h
Go to the documentation of this file.
1 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
3 
4 #pragma once
5 
6 #ifndef SPDLOG_HEADER_ONLY
8 #endif
9 
11 #include <spdlog/details/log_msg.h>
12 #include <spdlog/details/os.h>
13 #include <spdlog/fmt/fmt.h>
14 #include <spdlog/formatter.h>
15 
16 #include <algorithm>
17 #include <array>
18 #include <chrono>
19 #include <ctime>
20 #include <cctype>
21 #include <cstring>
22 #include <iterator>
23 #include <memory>
24 #include <mutex>
25 #include <string>
26 #include <thread>
27 #include <utility>
28 #include <vector>
29 
30 namespace spdlog {
31 namespace details {
32 
34 // name & level pattern appender
36 
38 {
39 public:
40  scoped_padder(size_t wrapped_size, const padding_info &padinfo, memory_buf_t &dest)
41  : padinfo_(padinfo)
42  , dest_(dest)
43  {
44  remaining_pad_ = static_cast<long>(padinfo.width_) - static_cast<long>(wrapped_size);
45  if (remaining_pad_ <= 0)
46  {
47  return;
48  }
49 
51  {
53  remaining_pad_ = 0;
54  }
56  {
57  auto half_pad = remaining_pad_ / 2;
58  auto reminder = remaining_pad_ & 1;
59  pad_it(half_pad);
60  remaining_pad_ = half_pad + reminder; // for the right side
61  }
62  }
63 
64  template<typename T>
65  static unsigned int count_digits(T n)
66  {
68  }
69 
71  {
72  if (remaining_pad_ >= 0)
73  {
75  }
76  else if (padinfo_.truncate_)
77  {
78  long new_size = static_cast<long>(dest_.size()) + remaining_pad_;
79  dest_.resize(static_cast<size_t>(new_size));
80  }
81  }
82 
83 private:
84  void pad_it(long count)
85  {
87  }
88 
93 };
94 
96 {
97  null_scoped_padder(size_t /*wrapped_size*/, const padding_info & /*padinfo*/, memory_buf_t & /*dest*/) {}
98 
99  template<typename T>
100  static unsigned int count_digits(T /* number */)
101  {
102  return 0;
103  }
104 };
105 
106 template<typename ScopedPadder>
107 class name_formatter final : public flag_formatter
108 {
109 public:
110  explicit name_formatter(padding_info padinfo)
111  : flag_formatter(padinfo)
112  {}
113 
114  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
115  {
116  ScopedPadder p(msg.logger_name.size(), padinfo_, dest);
118  }
119 };
120 
121 // log level appender
122 template<typename ScopedPadder>
123 class level_formatter final : public flag_formatter
124 {
125 public:
126  explicit level_formatter(padding_info padinfo)
127  : flag_formatter(padinfo)
128  {}
129 
130  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
131  {
132  const string_view_t &level_name = level::to_string_view(msg.level);
133  ScopedPadder p(level_name.size(), padinfo_, dest);
134  fmt_helper::append_string_view(level_name, dest);
135  }
136 };
137 
138 // short log level appender
139 template<typename ScopedPadder>
141 {
142 public:
144  : flag_formatter(padinfo)
145  {}
146 
147  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
148  {
149  string_view_t level_name{level::to_short_c_str(msg.level)};
150  ScopedPadder p(level_name.size(), padinfo_, dest);
151  fmt_helper::append_string_view(level_name, dest);
152  }
153 };
154 
156 // Date time pattern appenders
158 
159 static const char *ampm(const tm &t)
160 {
161  return t.tm_hour >= 12 ? "PM" : "AM";
162 }
163 
164 static int to12h(const tm &t)
165 {
166  return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour;
167 }
168 
169 // Abbreviated weekday name
170 static std::array<const char *, 7> days{{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}};
171 
172 template<typename ScopedPadder>
173 class a_formatter final : public flag_formatter
174 {
175 public:
176  explicit a_formatter(padding_info padinfo)
177  : flag_formatter(padinfo)
178  {}
179 
180  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
181  {
182  string_view_t field_value{days[static_cast<size_t>(tm_time.tm_wday)]};
183  ScopedPadder p(field_value.size(), padinfo_, dest);
184  fmt_helper::append_string_view(field_value, dest);
185  }
186 };
187 
188 // Full weekday name
189 static std::array<const char *, 7> full_days{{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}};
190 
191 template<typename ScopedPadder>
193 {
194 public:
195  explicit A_formatter(padding_info padinfo)
196  : flag_formatter(padinfo)
197  {}
198 
199  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
200  {
201  string_view_t field_value{full_days[static_cast<size_t>(tm_time.tm_wday)]};
202  ScopedPadder p(field_value.size(), padinfo_, dest);
203  fmt_helper::append_string_view(field_value, dest);
204  }
205 };
206 
207 // Abbreviated month
208 static const std::array<const char *, 12> months{{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}};
209 
210 template<typename ScopedPadder>
211 class b_formatter final : public flag_formatter
212 {
213 public:
214  explicit b_formatter(padding_info padinfo)
215  : flag_formatter(padinfo)
216  {}
217 
218  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
219  {
220  string_view_t field_value{months[static_cast<size_t>(tm_time.tm_mon)]};
221  ScopedPadder p(field_value.size(), padinfo_, dest);
222  fmt_helper::append_string_view(field_value, dest);
223  }
224 };
225 
226 // Full month name
227 static const std::array<const char *, 12> full_months{
228  {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}};
229 
230 template<typename ScopedPadder>
231 class B_formatter final : public flag_formatter
232 {
233 public:
234  explicit B_formatter(padding_info padinfo)
235  : flag_formatter(padinfo)
236  {}
237 
238  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
239  {
240  string_view_t field_value{full_months[static_cast<size_t>(tm_time.tm_mon)]};
241  ScopedPadder p(field_value.size(), padinfo_, dest);
242  fmt_helper::append_string_view(field_value, dest);
243  }
244 };
245 
246 // Date and time representation (Thu Aug 23 15:35:46 2014)
247 template<typename ScopedPadder>
248 class c_formatter final : public flag_formatter
249 {
250 public:
251  explicit c_formatter(padding_info padinfo)
252  : flag_formatter(padinfo)
253  {}
254 
255  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
256  {
257  const size_t field_size = 24;
258  ScopedPadder p(field_size, padinfo_, dest);
259 
260  fmt_helper::append_string_view(days[static_cast<size_t>(tm_time.tm_wday)], dest);
261  dest.push_back(' ');
262  fmt_helper::append_string_view(months[static_cast<size_t>(tm_time.tm_mon)], dest);
263  dest.push_back(' ');
264  fmt_helper::append_int(tm_time.tm_mday, dest);
265  dest.push_back(' ');
266  // time
267 
268  fmt_helper::pad2(tm_time.tm_hour, dest);
269  dest.push_back(':');
270  fmt_helper::pad2(tm_time.tm_min, dest);
271  dest.push_back(':');
272  fmt_helper::pad2(tm_time.tm_sec, dest);
273  dest.push_back(' ');
274  fmt_helper::append_int(tm_time.tm_year + 1900, dest);
275  }
276 };
277 
278 // year - 2 digit
279 template<typename ScopedPadder>
280 class C_formatter final : public flag_formatter
281 {
282 public:
283  explicit C_formatter(padding_info padinfo)
284  : flag_formatter(padinfo)
285  {}
286 
287  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
288  {
289  const size_t field_size = 2;
290  ScopedPadder p(field_size, padinfo_, dest);
291  fmt_helper::pad2(tm_time.tm_year % 100, dest);
292  }
293 };
294 
295 // Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
296 template<typename ScopedPadder>
297 class D_formatter final : public flag_formatter
298 {
299 public:
300  explicit D_formatter(padding_info padinfo)
301  : flag_formatter(padinfo)
302  {}
303 
304  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
305  {
306  const size_t field_size = 10;
307  ScopedPadder p(field_size, padinfo_, dest);
308 
309  fmt_helper::pad2(tm_time.tm_mon + 1, dest);
310  dest.push_back('/');
311  fmt_helper::pad2(tm_time.tm_mday, dest);
312  dest.push_back('/');
313  fmt_helper::pad2(tm_time.tm_year % 100, dest);
314  }
315 };
316 
317 // year - 4 digit
318 template<typename ScopedPadder>
319 class Y_formatter final : public flag_formatter
320 {
321 public:
322  explicit Y_formatter(padding_info padinfo)
323  : flag_formatter(padinfo)
324  {}
325 
326  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
327  {
328  const size_t field_size = 4;
329  ScopedPadder p(field_size, padinfo_, dest);
330  fmt_helper::append_int(tm_time.tm_year + 1900, dest);
331  }
332 };
333 
334 // month 1-12
335 template<typename ScopedPadder>
336 class m_formatter final : public flag_formatter
337 {
338 public:
339  explicit m_formatter(padding_info padinfo)
340  : flag_formatter(padinfo)
341  {}
342 
343  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
344  {
345  const size_t field_size = 2;
346  ScopedPadder p(field_size, padinfo_, dest);
347  fmt_helper::pad2(tm_time.tm_mon + 1, dest);
348  }
349 };
350 
351 // day of month 1-31
352 template<typename ScopedPadder>
353 class d_formatter final : public flag_formatter
354 {
355 public:
356  explicit d_formatter(padding_info padinfo)
357  : flag_formatter(padinfo)
358  {}
359 
360  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
361  {
362  const size_t field_size = 2;
363  ScopedPadder p(field_size, padinfo_, dest);
364  fmt_helper::pad2(tm_time.tm_mday, dest);
365  }
366 };
367 
368 // hours in 24 format 0-23
369 template<typename ScopedPadder>
370 class H_formatter final : public flag_formatter
371 {
372 public:
373  explicit H_formatter(padding_info padinfo)
374  : flag_formatter(padinfo)
375  {}
376 
377  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
378  {
379  const size_t field_size = 2;
380  ScopedPadder p(field_size, padinfo_, dest);
381  fmt_helper::pad2(tm_time.tm_hour, dest);
382  }
383 };
384 
385 // hours in 12 format 1-12
386 template<typename ScopedPadder>
387 class I_formatter final : public flag_formatter
388 {
389 public:
390  explicit I_formatter(padding_info padinfo)
391  : flag_formatter(padinfo)
392  {}
393 
394  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
395  {
396  const size_t field_size = 2;
397  ScopedPadder p(field_size, padinfo_, dest);
398  fmt_helper::pad2(to12h(tm_time), dest);
399  }
400 };
401 
402 // minutes 0-59
403 template<typename ScopedPadder>
404 class M_formatter final : public flag_formatter
405 {
406 public:
407  explicit M_formatter(padding_info padinfo)
408  : flag_formatter(padinfo)
409  {}
410 
411  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
412  {
413  const size_t field_size = 2;
414  ScopedPadder p(field_size, padinfo_, dest);
415  fmt_helper::pad2(tm_time.tm_min, dest);
416  }
417 };
418 
419 // seconds 0-59
420 template<typename ScopedPadder>
421 class S_formatter final : public flag_formatter
422 {
423 public:
424  explicit S_formatter(padding_info padinfo)
425  : flag_formatter(padinfo)
426  {}
427 
428  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
429  {
430  const size_t field_size = 2;
431  ScopedPadder p(field_size, padinfo_, dest);
432  fmt_helper::pad2(tm_time.tm_sec, dest);
433  }
434 };
435 
436 // milliseconds
437 template<typename ScopedPadder>
438 class e_formatter final : public flag_formatter
439 {
440 public:
441  explicit e_formatter(padding_info padinfo)
442  : flag_formatter(padinfo)
443  {}
444 
445  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
446  {
447  auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time);
448  const size_t field_size = 3;
449  ScopedPadder p(field_size, padinfo_, dest);
450  fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
451  }
452 };
453 
454 // microseconds
455 template<typename ScopedPadder>
456 class f_formatter final : public flag_formatter
457 {
458 public:
459  explicit f_formatter(padding_info padinfo)
460  : flag_formatter(padinfo)
461  {}
462 
463  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
464  {
465  auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time);
466 
467  const size_t field_size = 6;
468  ScopedPadder p(field_size, padinfo_, dest);
469  fmt_helper::pad6(static_cast<size_t>(micros.count()), dest);
470  }
471 };
472 
473 // nanoseconds
474 template<typename ScopedPadder>
475 class F_formatter final : public flag_formatter
476 {
477 public:
478  explicit F_formatter(padding_info padinfo)
479  : flag_formatter(padinfo)
480  {}
481 
482  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
483  {
484  auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time);
485  const size_t field_size = 9;
486  ScopedPadder p(field_size, padinfo_, dest);
487  fmt_helper::pad9(static_cast<size_t>(ns.count()), dest);
488  }
489 };
490 
491 // seconds since epoch
492 template<typename ScopedPadder>
493 class E_formatter final : public flag_formatter
494 {
495 public:
496  explicit E_formatter(padding_info padinfo)
497  : flag_formatter(padinfo)
498  {}
499 
500  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
501  {
502  const size_t field_size = 10;
503  ScopedPadder p(field_size, padinfo_, dest);
504  auto duration = msg.time.time_since_epoch();
505  auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
506  fmt_helper::append_int(seconds, dest);
507  }
508 };
509 
510 // AM/PM
511 template<typename ScopedPadder>
512 class p_formatter final : public flag_formatter
513 {
514 public:
515  explicit p_formatter(padding_info padinfo)
516  : flag_formatter(padinfo)
517  {}
518 
519  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
520  {
521  const size_t field_size = 2;
522  ScopedPadder p(field_size, padinfo_, dest);
523  fmt_helper::append_string_view(ampm(tm_time), dest);
524  }
525 };
526 
527 // 12 hour clock 02:55:02 pm
528 template<typename ScopedPadder>
529 class r_formatter final : public flag_formatter
530 {
531 public:
532  explicit r_formatter(padding_info padinfo)
533  : flag_formatter(padinfo)
534  {}
535 
536  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
537  {
538  const size_t field_size = 11;
539  ScopedPadder p(field_size, padinfo_, dest);
540 
541  fmt_helper::pad2(to12h(tm_time), dest);
542  dest.push_back(':');
543  fmt_helper::pad2(tm_time.tm_min, dest);
544  dest.push_back(':');
545  fmt_helper::pad2(tm_time.tm_sec, dest);
546  dest.push_back(' ');
547  fmt_helper::append_string_view(ampm(tm_time), dest);
548  }
549 };
550 
551 // 24-hour HH:MM time, equivalent to %H:%M
552 template<typename ScopedPadder>
553 class R_formatter final : public flag_formatter
554 {
555 public:
556  explicit R_formatter(padding_info padinfo)
557  : flag_formatter(padinfo)
558  {}
559 
560  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
561  {
562  const size_t field_size = 5;
563  ScopedPadder p(field_size, padinfo_, dest);
564 
565  fmt_helper::pad2(tm_time.tm_hour, dest);
566  dest.push_back(':');
567  fmt_helper::pad2(tm_time.tm_min, dest);
568  }
569 };
570 
571 // ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
572 template<typename ScopedPadder>
573 class T_formatter final : public flag_formatter
574 {
575 public:
576  explicit T_formatter(padding_info padinfo)
577  : flag_formatter(padinfo)
578  {}
579 
580  void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
581  {
582  const size_t field_size = 8;
583  ScopedPadder p(field_size, padinfo_, dest);
584 
585  fmt_helper::pad2(tm_time.tm_hour, dest);
586  dest.push_back(':');
587  fmt_helper::pad2(tm_time.tm_min, dest);
588  dest.push_back(':');
589  fmt_helper::pad2(tm_time.tm_sec, dest);
590  }
591 };
592 
593 // ISO 8601 offset from UTC in timezone (+-HH:MM)
594 template<typename ScopedPadder>
595 class z_formatter final : public flag_formatter
596 {
597 public:
598  explicit z_formatter(padding_info padinfo)
599  : flag_formatter(padinfo)
600  {}
601 
602  z_formatter() = default;
603  z_formatter(const z_formatter &) = delete;
604  z_formatter &operator=(const z_formatter &) = delete;
605 
606  void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override
607  {
608  const size_t field_size = 6;
609  ScopedPadder p(field_size, padinfo_, dest);
610 
611  auto total_minutes = get_cached_offset(msg, tm_time);
612  bool is_negative = total_minutes < 0;
613  if (is_negative)
614  {
615  total_minutes = -total_minutes;
616  dest.push_back('-');
617  }
618  else
619  {
620  dest.push_back('+');
621  }
622 
623  fmt_helper::pad2(total_minutes / 60, dest); // hours
624  dest.push_back(':');
625  fmt_helper::pad2(total_minutes % 60, dest); // minutes
626  }
627 
628 private:
629  log_clock::time_point last_update_{std::chrono::seconds(0)};
631 
632  int get_cached_offset(const log_msg &msg, const std::tm &tm_time)
633  {
634  // refresh every 10 seconds
635  if (msg.time - last_update_ >= std::chrono::seconds(10))
636  {
638  last_update_ = msg.time;
639  }
640  return offset_minutes_;
641  }
642 };
643 
644 // Thread id
645 template<typename ScopedPadder>
646 class t_formatter final : public flag_formatter
647 {
648 public:
649  explicit t_formatter(padding_info padinfo)
650  : flag_formatter(padinfo)
651  {}
652 
653  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
654  {
655  const auto field_size = ScopedPadder::count_digits(msg.thread_id);
656  ScopedPadder p(field_size, padinfo_, dest);
658  }
659 };
660 
661 // Current pid
662 template<typename ScopedPadder>
663 class pid_formatter final : public flag_formatter
664 {
665 public:
666  explicit pid_formatter(padding_info padinfo)
667  : flag_formatter(padinfo)
668  {}
669 
670  void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
671  {
672  const auto pid = static_cast<uint32_t>(details::os::pid());
673  auto field_size = ScopedPadder::count_digits(pid);
674  ScopedPadder p(field_size, padinfo_, dest);
676  }
677 };
678 
679 template<typename ScopedPadder>
680 class v_formatter final : public flag_formatter
681 {
682 public:
683  explicit v_formatter(padding_info padinfo)
684  : flag_formatter(padinfo)
685  {}
686 
687  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
688  {
689  ScopedPadder p(msg.payload.size(), padinfo_, dest);
691  }
692 };
693 
694 class ch_formatter final : public flag_formatter
695 {
696 public:
697  explicit ch_formatter(char ch)
698  : ch_(ch)
699  {}
700 
701  void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
702  {
703  dest.push_back(ch_);
704  }
705 
706 private:
707  char ch_;
708 };
709 
710 // aggregate user chars to display as is
712 {
713 public:
714  aggregate_formatter() = default;
715 
716  void add_ch(char ch)
717  {
718  str_ += ch;
719  }
720  void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
721  {
723  }
724 
725 private:
726  std::string str_;
727 };
728 
729 // mark the color range. expect it to be in the form of "%^colored text%$"
731 {
732 public:
734  : flag_formatter(padinfo)
735  {}
736 
737  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
738  {
739  msg.color_range_start = dest.size();
740  }
741 };
742 
744 {
745 public:
747  : flag_formatter(padinfo)
748  {}
749 
750  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
751  {
752  msg.color_range_end = dest.size();
753  }
754 };
755 
756 // print source location
757 template<typename ScopedPadder>
759 {
760 public:
762  : flag_formatter(padinfo)
763  {}
764 
765  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
766  {
767  if (msg.source.empty())
768  {
769  ScopedPadder p(0, padinfo_, dest);
770  return;
771  }
772 
773  size_t text_size;
774  if (padinfo_.enabled())
775  {
776  // calc text size for padding based on "filename:line"
778  }
779  else
780  {
781  text_size = 0;
782  }
783 
784  ScopedPadder p(text_size, padinfo_, dest);
786  dest.push_back(':');
788  }
789 };
790 
791 // print source filename
792 template<typename ScopedPadder>
794 {
795 public:
797  : flag_formatter(padinfo)
798  {}
799 
800  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
801  {
802  if (msg.source.empty())
803  {
804  ScopedPadder p(0, padinfo_, dest);
805  return;
806  }
807  size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) : 0;
808  ScopedPadder p(text_size, padinfo_, dest);
810  }
811 };
812 
813 template<typename ScopedPadder>
815 {
816 public:
818  : flag_formatter(padinfo)
819  {}
820 
821 #ifdef _MSC_VER
822 # pragma warning(push)
823 # pragma warning(disable : 4127) // consider using 'if constexpr' instead
824 #endif // _MSC_VER
825  static const char *basename(const char *filename)
826  {
827  // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
828  // the branch will be elided by optimizations
829  if (sizeof(os::folder_seps) == 2)
830  {
831  const char *rv = std::strrchr(filename, os::folder_seps[0]);
832  return rv != nullptr ? rv + 1 : filename;
833  }
834  else
835  {
836  const std::reverse_iterator<const char *> begin(filename + std::strlen(filename));
837  const std::reverse_iterator<const char *> end(filename);
838 
839  const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), std::end(os::folder_seps) - 1);
840  return it != end ? it.base() : filename;
841  }
842  }
843 #ifdef _MSC_VER
844 # pragma warning(pop)
845 #endif // _MSC_VER
846 
847  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
848  {
849  if (msg.source.empty())
850  {
851  ScopedPadder p(0, padinfo_, dest);
852  return;
853  }
854  auto filename = basename(msg.source.filename);
855  size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(filename) : 0;
856  ScopedPadder p(text_size, padinfo_, dest);
858  }
859 };
860 
861 template<typename ScopedPadder>
863 {
864 public:
866  : flag_formatter(padinfo)
867  {}
868 
869  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
870  {
871  if (msg.source.empty())
872  {
873  ScopedPadder p(0, padinfo_, dest);
874  return;
875  }
876 
877  auto field_size = ScopedPadder::count_digits(msg.source.line);
878  ScopedPadder p(field_size, padinfo_, dest);
880  }
881 };
882 
883 // print source funcname
884 template<typename ScopedPadder>
886 {
887 public:
889  : flag_formatter(padinfo)
890  {}
891 
892  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
893  {
894  if (msg.source.empty())
895  {
896  ScopedPadder p(0, padinfo_, dest);
897  return;
898  }
899  size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(msg.source.funcname) : 0;
900  ScopedPadder p(text_size, padinfo_, dest);
902  }
903 };
904 
905 // print elapsed time since last message
906 template<typename ScopedPadder, typename Units>
907 class elapsed_formatter final : public flag_formatter
908 {
909 public:
910  using DurationUnits = Units;
911 
912  explicit elapsed_formatter(padding_info padinfo)
913  : flag_formatter(padinfo)
915  {}
916 
917  void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
918  {
919  auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero());
920  auto delta_units = std::chrono::duration_cast<DurationUnits>(delta);
921  last_message_time_ = msg.time;
922  auto delta_count = static_cast<size_t>(delta_units.count());
923  auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count));
924  ScopedPadder p(n_digits, padinfo_, dest);
925  fmt_helper::append_int(delta_count, dest);
926  }
927 
928 private:
929  log_clock::time_point last_message_time_;
930 };
931 
932 // Full info formatter
933 // pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v
934 class full_formatter final : public flag_formatter
935 {
936 public:
937  explicit full_formatter(padding_info padinfo)
938  : flag_formatter(padinfo)
939  {}
940 
941  void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override
942  {
943  using std::chrono::duration_cast;
944  using std::chrono::milliseconds;
945  using std::chrono::seconds;
946 
947  // cache the date/time part for the next second.
948  auto duration = msg.time.time_since_epoch();
949  auto secs = duration_cast<seconds>(duration);
950 
951  if (cache_timestamp_ != secs || cached_datetime_.size() == 0)
952  {
955  fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_);
957 
958  fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_);
960 
961  fmt_helper::pad2(tm_time.tm_mday, cached_datetime_);
963 
964  fmt_helper::pad2(tm_time.tm_hour, cached_datetime_);
966 
967  fmt_helper::pad2(tm_time.tm_min, cached_datetime_);
969 
970  fmt_helper::pad2(tm_time.tm_sec, cached_datetime_);
972 
973  cache_timestamp_ = secs;
974  }
976 
977  auto millis = fmt_helper::time_fraction<milliseconds>(msg.time);
978  fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
979  dest.push_back(']');
980  dest.push_back(' ');
981 
982  // append logger name if exists
983  if (msg.logger_name.size() > 0)
984  {
985  dest.push_back('[');
987  dest.push_back(']');
988  dest.push_back(' ');
989  }
990 
991  dest.push_back('[');
992  // wrap the level name with color
993  msg.color_range_start = dest.size();
994  // fmt_helper::append_string_view(level::to_c_str(msg.level), dest);
996  msg.color_range_end = dest.size();
997  dest.push_back(']');
998  dest.push_back(' ');
999 
1000  // add source location if present
1001  if (!msg.source.empty())
1002  {
1003  dest.push_back('[');
1006  dest.push_back(':');
1007  fmt_helper::append_int(msg.source.line, dest);
1008  dest.push_back(']');
1009  dest.push_back(' ');
1010  }
1011  // fmt_helper::append_string_view(msg.msg(), dest);
1013  }
1014 
1015 private:
1016  std::chrono::seconds cache_timestamp_{0};
1018 };
1019 
1020 } // namespace details
1021 
1023  std::string pattern, pattern_time_type time_type, std::string eol, custom_flags custom_user_flags)
1024  : pattern_(std::move(pattern))
1025  , eol_(std::move(eol))
1026  , pattern_time_type_(time_type)
1027  , need_localtime_(false)
1028  , last_log_secs_(0)
1029  , custom_handlers_(std::move(custom_user_flags))
1030 {
1031  std::memset(&cached_tm_, 0, sizeof(cached_tm_));
1033 }
1034 
1035 // use by default full formatter for if pattern is not given
1037  : pattern_("%+")
1038  , eol_(std::move(eol))
1039  , pattern_time_type_(time_type)
1040  , need_localtime_(true)
1041  , last_log_secs_(0)
1042 {
1043  std::memset(&cached_tm_, 0, sizeof(cached_tm_));
1044  formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info{}));
1045 }
1046 
1047 SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
1048 {
1049  custom_flags cloned_custom_formatters;
1050  for (auto &it : custom_handlers_)
1051  {
1052  cloned_custom_formatters[it.first] = it.second->clone();
1053  }
1054  return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters));
1055 }
1056 
1058 {
1059  if (need_localtime_)
1060  {
1061  const auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
1062  if (secs != last_log_secs_)
1063  {
1064  cached_tm_ = get_time_(msg);
1065  last_log_secs_ = secs;
1066  }
1067  }
1068 
1069  for (auto &f : formatters_)
1070  {
1071  f->format(msg, cached_tm_, dest);
1072  }
1073  // write eol
1075 }
1076 
1078 {
1079  pattern_ = std::move(pattern);
1080  need_localtime_ = false;
1082 }
1083 
1085 {
1087  {
1088  return details::os::localtime(log_clock::to_time_t(msg.time));
1089  }
1090  return details::os::gmtime(log_clock::to_time_t(msg.time));
1091 }
1092 
1093 template<typename Padder>
1095 {
1096  // process custom flags
1097  auto it = custom_handlers_.find(flag);
1098  if (it != custom_handlers_.end())
1099  {
1100  auto custom_handler = it->second->clone();
1101  custom_handler->set_padding_info(padding);
1102  formatters_.push_back(std::move(custom_handler));
1103  return;
1104  }
1105 
1106  // process built-in flags
1107  switch (flag)
1108  {
1109  case ('+'): // default formatter
1110  formatters_.push_back(details::make_unique<details::full_formatter>(padding));
1111  need_localtime_ = true;
1112  break;
1113 
1114  case 'n': // logger name
1116  break;
1117 
1118  case 'l': // level
1120  break;
1121 
1122  case 'L': // short level
1124  break;
1125 
1126  case ('t'): // thread id
1128  break;
1129 
1130  case ('v'): // the message text
1132  break;
1133 
1134  case ('a'): // weekday
1136  need_localtime_ = true;
1137  break;
1138 
1139  case ('A'): // short weekday
1141  need_localtime_ = true;
1142  break;
1143 
1144  case ('b'):
1145  case ('h'): // month
1147  need_localtime_ = true;
1148  break;
1149 
1150  case ('B'): // short month
1152  need_localtime_ = true;
1153  break;
1154 
1155  case ('c'): // datetime
1157  need_localtime_ = true;
1158  break;
1159 
1160  case ('C'): // year 2 digits
1162  need_localtime_ = true;
1163  break;
1164 
1165  case ('Y'): // year 4 digits
1167  need_localtime_ = true;
1168  break;
1169 
1170  case ('D'):
1171  case ('x'): // datetime MM/DD/YY
1173  need_localtime_ = true;
1174  break;
1175 
1176  case ('m'): // month 1-12
1178  need_localtime_ = true;
1179  break;
1180 
1181  case ('d'): // day of month 1-31
1183  need_localtime_ = true;
1184  break;
1185 
1186  case ('H'): // hours 24
1188  need_localtime_ = true;
1189  break;
1190 
1191  case ('I'): // hours 12
1193  need_localtime_ = true;
1194  break;
1195 
1196  case ('M'): // minutes
1198  need_localtime_ = true;
1199  break;
1200 
1201  case ('S'): // seconds
1203  need_localtime_ = true;
1204  break;
1205 
1206  case ('e'): // milliseconds
1208  break;
1209 
1210  case ('f'): // microseconds
1212  break;
1213 
1214  case ('F'): // nanoseconds
1216  break;
1217 
1218  case ('E'): // seconds since epoch
1220  break;
1221 
1222  case ('p'): // am/pm
1224  need_localtime_ = true;
1225  break;
1226 
1227  case ('r'): // 12 hour clock 02:55:02 pm
1229  need_localtime_ = true;
1230  break;
1231 
1232  case ('R'): // 24-hour HH:MM time
1234  need_localtime_ = true;
1235  break;
1236 
1237  case ('T'):
1238  case ('X'): // ISO 8601 time format (HH:MM:SS)
1240  need_localtime_ = true;
1241  break;
1242 
1243  case ('z'): // timezone
1245  need_localtime_ = true;
1246  break;
1247 
1248  case ('P'): // pid
1250  break;
1251 
1252  case ('^'): // color range start
1253  formatters_.push_back(details::make_unique<details::color_start_formatter>(padding));
1254  break;
1255 
1256  case ('$'): // color range end
1257  formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding));
1258  break;
1259 
1260  case ('@'): // source location (filename:filenumber)
1262  break;
1263 
1264  case ('s'): // short source filename - without directory name
1266  break;
1267 
1268  case ('g'): // full source filename
1270  break;
1271 
1272  case ('#'): // source line number
1274  break;
1275 
1276  case ('!'): // source funcname
1278  break;
1279 
1280  case ('%'): // % char
1281  formatters_.push_back(details::make_unique<details::ch_formatter>('%'));
1282  break;
1283 
1284  case ('u'): // elapsed time since last log message in nanos
1286  break;
1287 
1288  case ('i'): // elapsed time since last log message in micros
1290  break;
1291 
1292  case ('o'): // elapsed time since last log message in millis
1294  break;
1295 
1296  case ('O'): // elapsed time since last log message in seconds
1298  break;
1299 
1300  default: // Unknown flag appears as is
1301  auto unknown_flag = details::make_unique<details::aggregate_formatter>();
1302 
1303  if (!padding.truncate_)
1304  {
1305  unknown_flag->add_ch('%');
1306  unknown_flag->add_ch(flag);
1307  formatters_.push_back((std::move(unknown_flag)));
1308  }
1309  // fix issue #1617 (prev char was '!' and should have been treated as funcname flag instead of truncating flag)
1310  // spdlog::set_pattern("[%10!] %v") => "[ main] some message"
1311  // spdlog::set_pattern("[%3!!] %v") => "[mai] some message"
1312  else
1313  {
1314  padding.truncate_ = false;
1316  unknown_flag->add_ch(flag);
1317  formatters_.push_back((std::move(unknown_flag)));
1318  }
1319 
1320  break;
1321  }
1322 }
1323 
1324 // Extract given pad spec (e.g. %8X, %=8X, %-8!X, %8!X, %=8!X, %-8!X, %+8!X)
1325 // Advance the given it pass the end of the padding spec found (if any)
1326 // Return padding.
1327 SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end)
1328 {
1329  using details::padding_info;
1330  using details::scoped_padder;
1331  const size_t max_width = 64;
1332  if (it == end)
1333  {
1334  return padding_info{};
1335  }
1336 
1337  padding_info::pad_side side;
1338  switch (*it)
1339  {
1340  case '-':
1342  ++it;
1343  break;
1344  case '=':
1346  ++it;
1347  break;
1348  default:
1350  break;
1351  }
1352 
1353  if (it == end || !std::isdigit(static_cast<unsigned char>(*it)))
1354  {
1355  return padding_info{}; // no padding if no digit found here
1356  }
1357 
1358  auto width = static_cast<size_t>(*it) - '0';
1359  for (++it; it != end && std::isdigit(static_cast<unsigned char>(*it)); ++it)
1360  {
1361  auto digit = static_cast<size_t>(*it) - '0';
1362  width = width * 10 + digit;
1363  }
1364 
1365  // search for the optional truncate marker '!'
1366  bool truncate;
1367  if (it != end && *it == '!')
1368  {
1369  truncate = true;
1370  ++it;
1371  }
1372  else
1373  {
1374  truncate = false;
1375  }
1376  return details::padding_info{std::min<size_t>(width, max_width), side, truncate};
1377 }
1378 
1379 SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &pattern)
1380 {
1381  auto end = pattern.end();
1382  std::unique_ptr<details::aggregate_formatter> user_chars;
1383  formatters_.clear();
1384  for (auto it = pattern.begin(); it != end; ++it)
1385  {
1386  if (*it == '%')
1387  {
1388  if (user_chars) // append user chars found so far
1389  {
1390  formatters_.push_back(std::move(user_chars));
1391  }
1392 
1393  auto padding = handle_padspec_(++it, end);
1394 
1395  if (it != end)
1396  {
1397  if (padding.enabled())
1398  {
1399  handle_flag_<details::scoped_padder>(*it, padding);
1400  }
1401  else
1402  {
1403  handle_flag_<details::null_scoped_padder>(*it, padding);
1404  }
1405  }
1406  else
1407  {
1408  break;
1409  }
1410  }
1411  else // chars not following the % sign should be displayed as is
1412  {
1413  if (!user_chars)
1414  {
1415  user_chars = details::make_unique<details::aggregate_formatter>();
1416  }
1417  user_chars->add_ch(*it);
1418  }
1419  }
1420  if (user_chars) // append raw chars found so far
1421  {
1422  formatters_.push_back(std::move(user_chars));
1423  }
1424 }
1425 } // namespace spdlog
spdlog::details::F_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:482
spdlog::details::T_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:580
spdlog::level::to_string_view
const SPDLOG_INLINE string_view_t & to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition: common-inl.h:23
spdlog::details::Y_formatter
Definition: pattern_formatter-inl.h:319
spdlog::details::A_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:199
spdlog::pattern_formatter::need_localtime_
bool need_localtime_
Definition: pattern_formatter.h:106
spdlog::details::z_formatter::format
void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:606
spdlog::details::I_formatter::I_formatter
I_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:390
spdlog::details::source_linenum_formatter::source_linenum_formatter
source_linenum_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:865
spdlog::details::t_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:653
spdlog::details::to12h
static int to12h(const tm &t)
Definition: pattern_formatter-inl.h:164
spdlog::pattern_formatter::custom_handlers_
custom_flags custom_handlers_
Definition: pattern_formatter.h:110
spdlog::details::source_funcname_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:892
spdlog::details::R_formatter
Definition: pattern_formatter-inl.h:553
spdlog::details::padding_info
Definition: pattern_formatter.h:23
spdlog::source_loc::funcname
const char * funcname
Definition: common.h:305
spdlog::details::source_location_formatter
Definition: pattern_formatter-inl.h:758
spdlog::details::m_formatter::m_formatter
m_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:339
spdlog::details::S_formatter::S_formatter
S_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:424
spdlog::details::ch_formatter
Definition: pattern_formatter-inl.h:694
spdlog::details::elapsed_formatter::last_message_time_
log_clock::time_point last_message_time_
Definition: pattern_formatter-inl.h:929
spdlog::details::z_formatter::get_cached_offset
int get_cached_offset(const log_msg &msg, const std::tm &tm_time)
Definition: pattern_formatter-inl.h:632
spdlog::details::flag_formatter
Definition: pattern_formatter.h:50
spdlog::details::aggregate_formatter::aggregate_formatter
aggregate_formatter()=default
spdlog::source_loc::filename
const char * filename
Definition: common.h:303
spdlog::details::p_formatter
Definition: pattern_formatter-inl.h:512
fmt::v8::detail::buffer::push_back
void push_back(const T &value)
Definition: core.h:849
spdlog::details::aggregate_formatter::add_ch
void add_ch(char ch)
Definition: pattern_formatter-inl.h:716
spdlog::details::B_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:238
spdlog::details::E_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:500
spdlog::details::d_formatter
Definition: pattern_formatter-inl.h:353
spdlog::details::short_filename_formatter::basename
static const char * basename(const char *filename)
Definition: pattern_formatter-inl.h:825
spdlog::details::scoped_padder::padinfo_
const padding_info & padinfo_
Definition: pattern_formatter-inl.h:89
spdlog::details::log_msg::payload
string_view_t payload
Definition: log_msg.h:30
spdlog::string_view_t
fmt::basic_string_view< char > string_view_t
Definition: common.h:154
spdlog::details::source_linenum_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:869
spdlog::details::E_formatter
Definition: pattern_formatter-inl.h:493
spdlog::details::os::folder_seps
static const SPDLOG_CONSTEXPR char folder_seps[]
Definition: os.h:43
spdlog::pattern_formatter::handle_padspec_
static details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end)
Definition: pattern_formatter-inl.h:1327
spdlog::details::days
static std::array< const char *, 7 > days
Definition: pattern_formatter-inl.h:170
spdlog::details::source_funcname_formatter
Definition: pattern_formatter-inl.h:885
spdlog::details::short_level_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:147
spdlog::details::t_formatter::t_formatter
t_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:649
spdlog::details::a_formatter
Definition: pattern_formatter-inl.h:173
fmt::v8::detail::buffer::size
constexpr auto size() const -> size_t
Definition: core.h:820
p
for p
Definition: process_rx_frame.m:36
spdlog::details::padding_info::pad_side::center
@ center
spdlog::details::m_formatter
Definition: pattern_formatter-inl.h:336
spdlog::details::r_formatter
Definition: pattern_formatter-inl.h:529
fmt::v8::basic_string_view
Definition: core.h:448
spdlog::details::scoped_padder::pad_it
void pad_it(long count)
Definition: pattern_formatter-inl.h:84
fmt::v8::detail::buffer::clear
void clear()
Definition: core.h:832
fmt::v8::align::right
@ right
Definition: core.h:2021
spdlog::details::elapsed_formatter::DurationUnits
Units DurationUnits
Definition: pattern_formatter-inl.h:910
spdlog::details::F_formatter::F_formatter
F_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:478
spdlog::details::z_formatter::z_formatter
z_formatter()=default
length
end IFFT Reshape the symbol vector into two different spatial streams length(tx_syms)/NUM_UE
spdlog::pattern_formatter::pattern_
std::string pattern_
Definition: pattern_formatter.h:103
spdlog::pattern_formatter::custom_flags
std::unordered_map< char, std::unique_ptr< custom_flag_formatter > > custom_flags
Definition: pattern_formatter.h:80
spdlog::details::a_formatter::a_formatter
a_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:176
spdlog::details::f_formatter
Definition: pattern_formatter-inl.h:456
fmt::v8::basic_string_view::size
constexpr auto size() const -> size_t
Definition: core.h:495
spdlog::details::padding_info::truncate_
bool truncate_
Definition: pattern_formatter.h:46
spdlog::details::p_formatter::p_formatter
p_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:515
spdlog::details::color_start_formatter::color_start_formatter
color_start_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:733
spdlog::details::os::now
SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT
Definition: os-inl.h:71
spdlog::details::z_formatter::operator=
z_formatter & operator=(const z_formatter &)=delete
spdlog::details::log_msg::color_range_end
size_t color_range_end
Definition: log_msg.h:27
spdlog::details::H_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:377
spdlog::details::m_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:343
spdlog::details::c_formatter
Definition: pattern_formatter-inl.h:248
spdlog::details::flag_formatter::padinfo_
padding_info padinfo_
Definition: pattern_formatter.h:61
count
count
Definition: inspect_agora_results.m:96
spdlog::details::short_filename_formatter::short_filename_formatter
short_filename_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:817
spdlog::details::c_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:255
spdlog::details::scoped_padder::~scoped_padder
~scoped_padder()
Definition: pattern_formatter-inl.h:70
spdlog::details::full_formatter::cached_datetime_
memory_buf_t cached_datetime_
Definition: pattern_formatter-inl.h:1017
spdlog::details::scoped_padder::dest_
memory_buf_t & dest_
Definition: pattern_formatter-inl.h:90
fmt::v8::detail::is_negative
auto is_negative(T value) -> bool
Definition: format.h:888
spdlog::details::v_formatter::v_formatter
v_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:683
spdlog::details::color_start_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:737
spdlog::details::os::utc_minutes_offset
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
Definition: os-inl.h:263
spdlog::log_clock
std::chrono::system_clock log_clock
Definition: common.h:126
spdlog::details::level_formatter
Definition: pattern_formatter-inl.h:123
spdlog::details::e_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:445
spdlog::details::source_location_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:765
T
T
Definition: simulate_performance.m:4
spdlog::details::aggregate_formatter::str_
std::string str_
Definition: pattern_formatter-inl.h:726
filename
filename
Definition: parse_all_dl.m:14
spdlog::details::I_formatter
Definition: pattern_formatter-inl.h:387
spdlog::details::T_formatter
Definition: pattern_formatter-inl.h:573
spdlog::pattern_formatter::compile_pattern_
void compile_pattern_(const std::string &pattern)
Definition: pattern_formatter-inl.h:1379
spdlog::details::r_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:536
fmt_helper.h
fmt::v8::basic_memory_buffer
Definition: format.h:677
spdlog::details::B_formatter
Definition: pattern_formatter-inl.h:231
spdlog::details::name_formatter
Definition: pattern_formatter-inl.h:107
spdlog
Definition: async.h:25
spdlog::details::scoped_padder::remaining_pad_
long remaining_pad_
Definition: pattern_formatter-inl.h:91
spdlog::details::b_formatter::b_formatter
b_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:214
spdlog::details::scoped_padder::count_digits
static unsigned int count_digits(T n)
Definition: pattern_formatter-inl.h:65
spdlog::details::padding_info::side_
pad_side side_
Definition: pattern_formatter.h:45
spdlog::details::short_filename_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:847
fmt::v8::basic_memory_buffer::resize
void resize(size_t count)
Definition: format.h:763
spdlog::details::os::gmtime
SPDLOG_INLINE std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
Definition: os-inl.h:103
spdlog::details::full_formatter
Definition: pattern_formatter-inl.h:934
nlohmann::json_v3_11_1NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON::detail2::begin
begin_tag begin(T &&...)
spdlog::level::to_short_c_str
const SPDLOG_INLINE char * to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
Definition: common-inl.h:28
spdlog::details::aggregate_formatter
Definition: pattern_formatter-inl.h:711
spdlog::details::e_formatter::e_formatter
e_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:441
spdlog::details::z_formatter::offset_minutes_
int offset_minutes_
Definition: pattern_formatter-inl.h:630
spdlog::details::M_formatter::M_formatter
M_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:407
spdlog::details::Y_formatter::Y_formatter
Y_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:322
spdlog::details::months
static const std::array< const char *, 12 > months
Definition: pattern_formatter-inl.h:208
spdlog::details::d_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:360
fmt::v8::align::center
@ center
Definition: core.h:2021
spdlog::details::S_formatter
Definition: pattern_formatter-inl.h:421
spdlog::pattern_formatter::handle_flag_
void handle_flag_(char flag, details::padding_info padding)
fmt::v8::detail::buffer::begin
auto begin() -> T *
Definition: core.h:813
spdlog::details::D_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:304
spdlog::details::d_formatter::d_formatter
d_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:356
spdlog::details::null_scoped_padder::null_scoped_padder
null_scoped_padder(size_t, const padding_info &, memory_buf_t &)
Definition: pattern_formatter-inl.h:97
spdlog::details::log_msg::logger_name
string_view_t logger_name
Definition: log_msg.h:20
spdlog::details::scoped_padder::spaces_
string_view_t spaces_
Definition: pattern_formatter-inl.h:92
spdlog::details::t_formatter
Definition: pattern_formatter-inl.h:646
spdlog::details::os::localtime
SPDLOG_INLINE std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
Definition: os-inl.h:84
spdlog::pattern_formatter::pattern_formatter
pattern_formatter(std::string pattern, pattern_time_type time_type=pattern_time_type::local, std::string eol=spdlog::details::os::default_eol, custom_flags custom_user_flags=custom_flags())
Definition: pattern_formatter-inl.h:1022
SPDLOG_INLINE
#define SPDLOG_INLINE
Definition: common.h:42
os.h
spdlog::details::log_msg::thread_id
size_t thread_id
Definition: log_msg.h:23
spdlog::details::f_formatter::f_formatter
f_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:459
spdlog::details::v_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:687
spdlog::details::Y_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:326
spdlog::details::make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: common.h:334
spdlog::details::fmt_helper::pad3
void pad3(T n, memory_buf_t &dest)
Definition: fmt_helper.h:126
spdlog::source_loc::line
int line
Definition: common.h:304
fmt::v8::detail::buffer::end
auto end() -> T *
Definition: core.h:814
spdlog::details::log_msg::level
level::level_enum level
Definition: log_msg.h:21
spdlog::details::pid_formatter::pid_formatter
pid_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:666
spdlog::details::e_formatter
Definition: pattern_formatter-inl.h:438
fmt::v8::basic_memory_buffer::append
void append(const ContiguousRange &range)
Definition: format.h:771
spdlog::pattern_formatter::pattern_time_type_
pattern_time_type pattern_time_type_
Definition: pattern_formatter.h:105
spdlog::details::os::pid
SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT
Definition: os-inl.h:404
spdlog::details::B_formatter::B_formatter
B_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:234
spdlog::details::elapsed_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:917
spdlog::details::I_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:394
spdlog::pattern_formatter::last_log_secs_
std::chrono::seconds last_log_secs_
Definition: pattern_formatter.h:108
spdlog::details::v_formatter
Definition: pattern_formatter-inl.h:680
spdlog::details::null_scoped_padder
Definition: pattern_formatter-inl.h:95
spdlog::details::z_formatter::z_formatter
z_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:598
spdlog::details::source_filename_formatter::source_filename_formatter
source_filename_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:796
spdlog::pattern_formatter::set_pattern
void set_pattern(std::string pattern)
Definition: pattern_formatter-inl.h:1077
spdlog::details::D_formatter::D_formatter
D_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:300
spdlog::details::null_scoped_padder::count_digits
static unsigned int count_digits(T)
Definition: pattern_formatter-inl.h:100
spdlog::details::full_formatter::format
void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:941
spdlog::details::full_formatter::full_formatter
full_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:937
n
n
Definition: simulate_performance.m:1
spdlog::details::M_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:411
spdlog::details::aggregate_formatter::format
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:720
fmt::v8::basic_string_view::data
constexpr auto data() const -> const Char *
Definition: core.h:492
spdlog::details::elapsed_formatter
Definition: pattern_formatter-inl.h:907
spdlog::details::source_filename_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:800
spdlog::pattern_formatter::formatters_
std::vector< std::unique_ptr< details::flag_formatter > > formatters_
Definition: pattern_formatter.h:109
spdlog::pattern_time_type::local
@ local
spdlog::details::log_msg
Definition: log_msg.h:11
spdlog::details::D_formatter
Definition: pattern_formatter-inl.h:297
spdlog::details::full_formatter::cache_timestamp_
std::chrono::seconds cache_timestamp_
Definition: pattern_formatter-inl.h:1016
spdlog::details::fmt_helper::count_digits
unsigned int count_digits(T n)
Definition: fmt_helper.h:83
spdlog::details::T_formatter::T_formatter
T_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:576
spdlog::details::fmt_helper::append_string_view
void append_string_view(spdlog::string_view_t view, memory_buf_t &dest)
Definition: fmt_helper.h:26
spdlog::pattern_time_type
pattern_time_type
Definition: common.h:267
spdlog::details::color_stop_formatter
Definition: pattern_formatter-inl.h:743
spdlog::details::full_days
static std::array< const char *, 7 > full_days
Definition: pattern_formatter-inl.h:189
spdlog::details::f_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:463
spdlog::details::color_stop_formatter::color_stop_formatter
color_stop_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:746
std
Definition: json.hpp:5213
pattern_formatter.h
spdlog::details::source_funcname_formatter::source_funcname_formatter
source_funcname_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:888
spdlog::details::name_formatter::name_formatter
name_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:110
spdlog::details::A_formatter
Definition: pattern_formatter-inl.h:192
spdlog::pattern_formatter::cached_tm_
std::tm cached_tm_
Definition: pattern_formatter.h:107
spdlog::details::padding_info::pad_side::left
@ left
spdlog::details::M_formatter
Definition: pattern_formatter-inl.h:404
spdlog::details::padding_info::enabled
bool enabled() const
Definition: pattern_formatter.h:40
spdlog::details::full_months
static const std::array< const char *, 12 > full_months
Definition: pattern_formatter-inl.h:227
spdlog::details::short_level_formatter
Definition: pattern_formatter-inl.h:140
spdlog::details::R_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:560
spdlog::details::scoped_padder
Definition: pattern_formatter-inl.h:37
spdlog::details::name_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:114
spdlog::details::F_formatter
Definition: pattern_formatter-inl.h:475
spdlog::details::z_formatter
Definition: pattern_formatter-inl.h:595
spdlog::details::short_level_formatter::short_level_formatter
short_level_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:143
spdlog::details::color_start_formatter
Definition: pattern_formatter-inl.h:730
spdlog::details::log_msg::source
source_loc source
Definition: log_msg.h:29
spdlog::details::E_formatter::E_formatter
E_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:496
spdlog::details::b_formatter
Definition: pattern_formatter-inl.h:211
spdlog::details::log_msg::color_range_start
size_t color_range_start
Definition: log_msg.h:26
spdlog::details::scoped_padder::scoped_padder
scoped_padder(size_t wrapped_size, const padding_info &padinfo, memory_buf_t &dest)
Definition: pattern_formatter-inl.h:40
spdlog::details::source_linenum_formatter
Definition: pattern_formatter-inl.h:862
spdlog::details::C_formatter
Definition: pattern_formatter-inl.h:280
spdlog::details::ampm
static const char * ampm(const tm &t)
Definition: pattern_formatter-inl.h:159
spdlog::pattern_formatter::eol_
std::string eol_
Definition: pattern_formatter.h:104
formatter.h
spdlog::details::color_stop_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:750
spdlog::details::level_formatter::level_formatter
level_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:126
spdlog::details::padding_info::width_
size_t width_
Definition: pattern_formatter.h:44
spdlog::details::pid_formatter::format
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:670
spdlog::details::S_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:428
spdlog::details::c_formatter::c_formatter
c_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:251
spdlog::details::R_formatter::R_formatter
R_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:556
spdlog::details::z_formatter::last_update_
log_clock::time_point last_update_
Definition: pattern_formatter-inl.h:629
spdlog::details::C_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:287
spdlog::details::ch_formatter::ch_
char ch_
Definition: pattern_formatter-inl.h:707
spdlog::details::fmt_helper::pad6
void pad6(T n, memory_buf_t &dest)
Definition: fmt_helper.h:143
spdlog::details::level_formatter::format
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:130
spdlog::details::fmt_helper::append_int
void append_int(T n, memory_buf_t &dest)
Definition: fmt_helper.h:52
spdlog::details::A_formatter::A_formatter
A_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:195
log_msg.h
spdlog::details::C_formatter::C_formatter
C_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:283
spdlog::details::ch_formatter::format
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:701
spdlog::details::fmt_helper::pad2
void pad2(int n, memory_buf_t &dest)
Definition: fmt_helper.h:101
max
max(y1, y1_1)
spdlog::details::H_formatter
Definition: pattern_formatter-inl.h:370
spdlog::details::source_filename_formatter
Definition: pattern_formatter-inl.h:793
spdlog::details::elapsed_formatter::elapsed_formatter
elapsed_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:912
spdlog::details::pid_formatter
Definition: pattern_formatter-inl.h:663
spdlog::pattern_formatter::clone
std::unique_ptr< formatter > clone() const override
Definition: pattern_formatter-inl.h:1047
fmt.h
spdlog::details::a_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:180
spdlog::details::ch_formatter::ch_formatter
ch_formatter(char ch)
Definition: pattern_formatter-inl.h:697
spdlog::details::short_filename_formatter
Definition: pattern_formatter-inl.h:814
spdlog::pattern_formatter::get_time_
std::tm get_time_(const details::log_msg &msg)
Definition: pattern_formatter-inl.h:1084
spdlog::details::H_formatter::H_formatter
H_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:373
spdlog::details::log_msg::time
log_clock::time_point time
Definition: log_msg.h:22
spdlog::details::b_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:218
spdlog::source_loc::empty
constexpr bool empty() const noexcept
Definition: common.h:299
spdlog::details::source_location_formatter::source_location_formatter
source_location_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:761
nlohmann::json_v3_11_1NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON::detail2::end
end_tag end(T &&...)
spdlog::pattern_formatter::format
void format(const details::log_msg &msg, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:1057
spdlog::details::p_formatter::format
void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override
Definition: pattern_formatter-inl.h:519
spdlog::details::fmt_helper::pad9
void pad9(T n, memory_buf_t &dest)
Definition: fmt_helper.h:149
spdlog::details::r_formatter::r_formatter
r_formatter(padding_info padinfo)
Definition: pattern_formatter-inl.h:532