/src/spdlog/include/spdlog/pattern_formatter-inl.h
Line | Count | Source |
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 |
7 | | #include <spdlog/pattern_formatter.h> |
8 | | #endif |
9 | | |
10 | | #include <spdlog/details/fmt_helper.h> |
11 | | #include <spdlog/details/log_msg.h> |
12 | | #include <spdlog/details/os.h> |
13 | | |
14 | | #ifndef SPDLOG_NO_TLS |
15 | | #include <spdlog/mdc.h> |
16 | | #endif |
17 | | |
18 | | #include <spdlog/fmt/fmt.h> |
19 | | #include <spdlog/formatter.h> |
20 | | |
21 | | #include <algorithm> |
22 | | #include <array> |
23 | | #include <cctype> |
24 | | #include <chrono> |
25 | | #include <cstring> |
26 | | #include <ctime> |
27 | | #include <iterator> |
28 | | #include <memory> |
29 | | #include <mutex> |
30 | | #include <string> |
31 | | #include <thread> |
32 | | #include <utility> |
33 | | #include <vector> |
34 | | |
35 | | namespace spdlog { |
36 | | namespace details { |
37 | | |
38 | | /////////////////////////////////////////////////////////////////////// |
39 | | // name & level pattern appender |
40 | | /////////////////////////////////////////////////////////////////////// |
41 | | |
42 | | class scoped_padder { |
43 | | public: |
44 | | scoped_padder(size_t wrapped_size, const padding_info &padinfo, memory_buf_t &dest) |
45 | 729k | : padinfo_(padinfo), |
46 | 729k | dest_(dest) { |
47 | 729k | remaining_pad_ = static_cast<long>(padinfo.width_) - static_cast<long>(wrapped_size); |
48 | 729k | if (remaining_pad_ <= 0) { |
49 | 462k | return; |
50 | 462k | } |
51 | | |
52 | 266k | if (padinfo_.side_ == padding_info::pad_side::left) { |
53 | 249k | pad_it(remaining_pad_); |
54 | 249k | remaining_pad_ = 0; |
55 | 249k | } else if (padinfo_.side_ == padding_info::pad_side::center) { |
56 | 13.2k | auto half_pad = remaining_pad_ / 2; |
57 | 13.2k | auto reminder = remaining_pad_ & 1; |
58 | 13.2k | pad_it(half_pad); |
59 | 13.2k | remaining_pad_ = half_pad + reminder; // for the right side |
60 | 13.2k | } |
61 | 266k | } |
62 | | |
63 | | template <typename T> |
64 | 227k | static unsigned int count_digits(T n) { |
65 | 227k | return fmt_helper::count_digits(n); |
66 | 227k | } unsigned int spdlog::details::scoped_padder::count_digits<unsigned long>(unsigned long) Line | Count | Source | 64 | 226k | static unsigned int count_digits(T n) { | 65 | 226k | return fmt_helper::count_digits(n); | 66 | 226k | } |
unsigned int spdlog::details::scoped_padder::count_digits<unsigned int>(unsigned int) Line | Count | Source | 64 | 1.59k | static unsigned int count_digits(T n) { | 65 | 1.59k | return fmt_helper::count_digits(n); | 66 | 1.59k | } |
Unexecuted instantiation: unsigned int spdlog::details::scoped_padder::count_digits<int>(int) |
67 | | |
68 | 729k | ~scoped_padder() { |
69 | 729k | if (remaining_pad_ >= 0) { |
70 | 304k | pad_it(remaining_pad_); |
71 | 425k | } else if (padinfo_.truncate_) { |
72 | 6.28k | long new_size = static_cast<long>(dest_.size()) + remaining_pad_; |
73 | 6.28k | if (new_size < 0) { |
74 | 0 | new_size = 0; |
75 | 0 | } |
76 | 6.28k | dest_.resize(static_cast<size_t>(new_size)); |
77 | 6.28k | } |
78 | 729k | } |
79 | | |
80 | | private: |
81 | 567k | void pad_it(long count) { |
82 | 567k | fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast<size_t>(count)), |
83 | 567k | dest_); |
84 | 567k | } |
85 | | |
86 | | const padding_info &padinfo_; |
87 | | memory_buf_t &dest_; |
88 | | long remaining_pad_; |
89 | | string_view_t spaces_{" ", 64}; |
90 | | }; |
91 | | |
92 | | struct null_scoped_padder { |
93 | | null_scoped_padder(size_t /*wrapped_size*/, |
94 | | const padding_info & /*padinfo*/, |
95 | 697k | memory_buf_t & /*dest*/) {} |
96 | | |
97 | | template <typename T> |
98 | 291k | static unsigned int count_digits(T /* number */) { |
99 | 291k | return 0; |
100 | 291k | } unsigned int spdlog::details::null_scoped_padder::count_digits<unsigned long>(unsigned long) Line | Count | Source | 98 | 267k | static unsigned int count_digits(T /* number */) { | 99 | 267k | return 0; | 100 | 267k | } |
unsigned int spdlog::details::null_scoped_padder::count_digits<unsigned int>(unsigned int) Line | Count | Source | 98 | 23.6k | static unsigned int count_digits(T /* number */) { | 99 | 23.6k | return 0; | 100 | 23.6k | } |
Unexecuted instantiation: unsigned int spdlog::details::null_scoped_padder::count_digits<int>(int) |
101 | | }; |
102 | | |
103 | | template <typename ScopedPadder> |
104 | | class name_formatter final : public flag_formatter { |
105 | | public: |
106 | | explicit name_formatter(padding_info padinfo) |
107 | 124k | : flag_formatter(padinfo) {}spdlog::details::name_formatter<spdlog::details::scoped_padder>::name_formatter(spdlog::details::padding_info) Line | Count | Source | 107 | 70.7k | : flag_formatter(padinfo) {} |
spdlog::details::name_formatter<spdlog::details::null_scoped_padder>::name_formatter(spdlog::details::padding_info) Line | Count | Source | 107 | 54.0k | : flag_formatter(padinfo) {} |
|
108 | | |
109 | 33.3k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
110 | 33.3k | ScopedPadder p(msg.logger_name.size(), padinfo_, dest); |
111 | 33.3k | fmt_helper::append_string_view(msg.logger_name, dest); |
112 | 33.3k | } spdlog::details::name_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 109 | 20.4k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 110 | 20.4k | ScopedPadder p(msg.logger_name.size(), padinfo_, dest); | 111 | 20.4k | fmt_helper::append_string_view(msg.logger_name, dest); | 112 | 20.4k | } |
spdlog::details::name_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 109 | 12.8k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 110 | 12.8k | ScopedPadder p(msg.logger_name.size(), padinfo_, dest); | 111 | 12.8k | fmt_helper::append_string_view(msg.logger_name, dest); | 112 | 12.8k | } |
|
113 | | }; |
114 | | |
115 | | // log level appender |
116 | | template <typename ScopedPadder> |
117 | | class level_formatter final : public flag_formatter { |
118 | | public: |
119 | | explicit level_formatter(padding_info padinfo) |
120 | 59.9k | : flag_formatter(padinfo) {}spdlog::details::level_formatter<spdlog::details::scoped_padder>::level_formatter(spdlog::details::padding_info) Line | Count | Source | 120 | 28.6k | : flag_formatter(padinfo) {} |
spdlog::details::level_formatter<spdlog::details::null_scoped_padder>::level_formatter(spdlog::details::padding_info) Line | Count | Source | 120 | 31.3k | : flag_formatter(padinfo) {} |
|
121 | | |
122 | 13.5k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
123 | 13.5k | const string_view_t &level_name = level::to_string_view(msg.level); |
124 | 13.5k | ScopedPadder p(level_name.size(), padinfo_, dest); |
125 | 13.5k | fmt_helper::append_string_view(level_name, dest); |
126 | 13.5k | } spdlog::details::level_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 122 | 4.95k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 123 | 4.95k | const string_view_t &level_name = level::to_string_view(msg.level); | 124 | 4.95k | ScopedPadder p(level_name.size(), padinfo_, dest); | 125 | 4.95k | fmt_helper::append_string_view(level_name, dest); | 126 | 4.95k | } |
spdlog::details::level_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 122 | 8.57k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 123 | 8.57k | const string_view_t &level_name = level::to_string_view(msg.level); | 124 | 8.57k | ScopedPadder p(level_name.size(), padinfo_, dest); | 125 | 8.57k | fmt_helper::append_string_view(level_name, dest); | 126 | 8.57k | } |
|
127 | | }; |
128 | | |
129 | | // short log level appender |
130 | | template <typename ScopedPadder> |
131 | | class short_level_formatter final : public flag_formatter { |
132 | | public: |
133 | | explicit short_level_formatter(padding_info padinfo) |
134 | 155k | : flag_formatter(padinfo) {}spdlog::details::short_level_formatter<spdlog::details::scoped_padder>::short_level_formatter(spdlog::details::padding_info) Line | Count | Source | 134 | 42.9k | : flag_formatter(padinfo) {} |
spdlog::details::short_level_formatter<spdlog::details::null_scoped_padder>::short_level_formatter(spdlog::details::padding_info) Line | Count | Source | 134 | 112k | : flag_formatter(padinfo) {} |
|
135 | | |
136 | 31.7k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
137 | 31.7k | string_view_t level_name{level::to_short_c_str(msg.level)}; |
138 | 31.7k | ScopedPadder p(level_name.size(), padinfo_, dest); |
139 | 31.7k | fmt_helper::append_string_view(level_name, dest); |
140 | 31.7k | } spdlog::details::short_level_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 136 | 13.8k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 137 | 13.8k | string_view_t level_name{level::to_short_c_str(msg.level)}; | 138 | 13.8k | ScopedPadder p(level_name.size(), padinfo_, dest); | 139 | 13.8k | fmt_helper::append_string_view(level_name, dest); | 140 | 13.8k | } |
spdlog::details::short_level_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 136 | 17.9k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 137 | 17.9k | string_view_t level_name{level::to_short_c_str(msg.level)}; | 138 | 17.9k | ScopedPadder p(level_name.size(), padinfo_, dest); | 139 | 17.9k | fmt_helper::append_string_view(level_name, dest); | 140 | 17.9k | } |
|
141 | | }; |
142 | | |
143 | | /////////////////////////////////////////////////////////////////////// |
144 | | // Date time pattern appenders |
145 | | /////////////////////////////////////////////////////////////////////// |
146 | | |
147 | 31.6k | static const char *ampm(const tm &t) { return t.tm_hour >= 12 ? "PM" : "AM"; }Unexecuted instantiation: pattern_fuzzer.cc:spdlog::details::ampm(tm const&) Unexecuted instantiation: levels_fuzzer.cc:spdlog::details::ampm(tm const&) Unexecuted instantiation: log_fuzzer.cc:spdlog::details::ampm(tm const&) format_fuzzer.cc:spdlog::details::ampm(tm const&) Line | Count | Source | 147 | 31.6k | static const char *ampm(const tm &t) { return t.tm_hour >= 12 ? "PM" : "AM"; } |
Unexecuted instantiation: backtrace_fuzzer.cc:spdlog::details::ampm(tm const&) |
148 | | |
149 | 32.4k | static int to12h(const tm &t) { return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour; }Unexecuted instantiation: pattern_fuzzer.cc:spdlog::details::to12h(tm const&) Unexecuted instantiation: levels_fuzzer.cc:spdlog::details::to12h(tm const&) Unexecuted instantiation: log_fuzzer.cc:spdlog::details::to12h(tm const&) format_fuzzer.cc:spdlog::details::to12h(tm const&) Line | Count | Source | 149 | 32.4k | static int to12h(const tm &t) { return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour; } |
Unexecuted instantiation: backtrace_fuzzer.cc:spdlog::details::to12h(tm const&) |
150 | | |
151 | | // Abbreviated weekday name |
152 | | static std::array<const char *, 7> days{{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}}; |
153 | | |
154 | | template <typename ScopedPadder> |
155 | | class a_formatter final : public flag_formatter { |
156 | | public: |
157 | | explicit a_formatter(padding_info padinfo) |
158 | 61.2k | : flag_formatter(padinfo) {}spdlog::details::a_formatter<spdlog::details::scoped_padder>::a_formatter(spdlog::details::padding_info) Line | Count | Source | 158 | 36.5k | : flag_formatter(padinfo) {} |
spdlog::details::a_formatter<spdlog::details::null_scoped_padder>::a_formatter(spdlog::details::padding_info) Line | Count | Source | 158 | 24.7k | : flag_formatter(padinfo) {} |
|
159 | | |
160 | 7.88k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
161 | 7.88k | string_view_t field_value{days[static_cast<size_t>(tm_time.tm_wday)]}; |
162 | 7.88k | ScopedPadder p(field_value.size(), padinfo_, dest); |
163 | 7.88k | fmt_helper::append_string_view(field_value, dest); |
164 | 7.88k | } spdlog::details::a_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 160 | 4.20k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 161 | 4.20k | string_view_t field_value{days[static_cast<size_t>(tm_time.tm_wday)]}; | 162 | 4.20k | ScopedPadder p(field_value.size(), padinfo_, dest); | 163 | 4.20k | fmt_helper::append_string_view(field_value, dest); | 164 | 4.20k | } |
spdlog::details::a_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 160 | 3.68k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 161 | 3.68k | string_view_t field_value{days[static_cast<size_t>(tm_time.tm_wday)]}; | 162 | 3.68k | ScopedPadder p(field_value.size(), padinfo_, dest); | 163 | 3.68k | fmt_helper::append_string_view(field_value, dest); | 164 | 3.68k | } |
|
165 | | }; |
166 | | |
167 | | // Full weekday name |
168 | | static std::array<const char *, 7> full_days{ |
169 | | {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}}; |
170 | | |
171 | | template <typename ScopedPadder> |
172 | | class A_formatter : public flag_formatter { |
173 | | public: |
174 | | explicit A_formatter(padding_info padinfo) |
175 | 99.1k | : flag_formatter(padinfo) {}spdlog::details::A_formatter<spdlog::details::scoped_padder>::A_formatter(spdlog::details::padding_info) Line | Count | Source | 175 | 37.0k | : flag_formatter(padinfo) {} |
spdlog::details::A_formatter<spdlog::details::null_scoped_padder>::A_formatter(spdlog::details::padding_info) Line | Count | Source | 175 | 62.1k | : flag_formatter(padinfo) {} |
|
176 | | |
177 | 25.3k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
178 | 25.3k | string_view_t field_value{full_days[static_cast<size_t>(tm_time.tm_wday)]}; |
179 | 25.3k | ScopedPadder p(field_value.size(), padinfo_, dest); |
180 | 25.3k | fmt_helper::append_string_view(field_value, dest); |
181 | 25.3k | } spdlog::details::A_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 177 | 7.11k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 178 | 7.11k | string_view_t field_value{full_days[static_cast<size_t>(tm_time.tm_wday)]}; | 179 | 7.11k | ScopedPadder p(field_value.size(), padinfo_, dest); | 180 | 7.11k | fmt_helper::append_string_view(field_value, dest); | 181 | 7.11k | } |
spdlog::details::A_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 177 | 18.2k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 178 | 18.2k | string_view_t field_value{full_days[static_cast<size_t>(tm_time.tm_wday)]}; | 179 | 18.2k | ScopedPadder p(field_value.size(), padinfo_, dest); | 180 | 18.2k | fmt_helper::append_string_view(field_value, dest); | 181 | 18.2k | } |
|
182 | | }; |
183 | | |
184 | | // Abbreviated month |
185 | | static const std::array<const char *, 12> months{ |
186 | | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}}; |
187 | | |
188 | | template <typename ScopedPadder> |
189 | | class b_formatter final : public flag_formatter { |
190 | | public: |
191 | | explicit b_formatter(padding_info padinfo) |
192 | 184k | : flag_formatter(padinfo) {}spdlog::details::b_formatter<spdlog::details::scoped_padder>::b_formatter(spdlog::details::padding_info) Line | Count | Source | 192 | 29.2k | : flag_formatter(padinfo) {} |
spdlog::details::b_formatter<spdlog::details::null_scoped_padder>::b_formatter(spdlog::details::padding_info) Line | Count | Source | 192 | 154k | : flag_formatter(padinfo) {} |
|
193 | | |
194 | 51.3k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
195 | 51.3k | string_view_t field_value{months[static_cast<size_t>(tm_time.tm_mon)]}; |
196 | 51.3k | ScopedPadder p(field_value.size(), padinfo_, dest); |
197 | 51.3k | fmt_helper::append_string_view(field_value, dest); |
198 | 51.3k | } spdlog::details::b_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 194 | 5.77k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 195 | 5.77k | string_view_t field_value{months[static_cast<size_t>(tm_time.tm_mon)]}; | 196 | 5.77k | ScopedPadder p(field_value.size(), padinfo_, dest); | 197 | 5.77k | fmt_helper::append_string_view(field_value, dest); | 198 | 5.77k | } |
spdlog::details::b_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 194 | 45.5k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 195 | 45.5k | string_view_t field_value{months[static_cast<size_t>(tm_time.tm_mon)]}; | 196 | 45.5k | ScopedPadder p(field_value.size(), padinfo_, dest); | 197 | 45.5k | fmt_helper::append_string_view(field_value, dest); | 198 | 45.5k | } |
|
199 | | }; |
200 | | |
201 | | // Full month name |
202 | | static const std::array<const char *, 12> full_months{{"January", "February", "March", "April", |
203 | | "May", "June", "July", "August", "September", |
204 | | "October", "November", "December"}}; |
205 | | |
206 | | template <typename ScopedPadder> |
207 | | class B_formatter final : public flag_formatter { |
208 | | public: |
209 | | explicit B_formatter(padding_info padinfo) |
210 | 117k | : flag_formatter(padinfo) {}spdlog::details::B_formatter<spdlog::details::scoped_padder>::B_formatter(spdlog::details::padding_info) Line | Count | Source | 210 | 53.6k | : flag_formatter(padinfo) {} |
spdlog::details::B_formatter<spdlog::details::null_scoped_padder>::B_formatter(spdlog::details::padding_info) Line | Count | Source | 210 | 63.9k | : flag_formatter(padinfo) {} |
|
211 | | |
212 | 33.2k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
213 | 33.2k | string_view_t field_value{full_months[static_cast<size_t>(tm_time.tm_mon)]}; |
214 | 33.2k | ScopedPadder p(field_value.size(), padinfo_, dest); |
215 | 33.2k | fmt_helper::append_string_view(field_value, dest); |
216 | 33.2k | } spdlog::details::B_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 212 | 14.8k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 213 | 14.8k | string_view_t field_value{full_months[static_cast<size_t>(tm_time.tm_mon)]}; | 214 | 14.8k | ScopedPadder p(field_value.size(), padinfo_, dest); | 215 | 14.8k | fmt_helper::append_string_view(field_value, dest); | 216 | 14.8k | } |
spdlog::details::B_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 212 | 18.4k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 213 | 18.4k | string_view_t field_value{full_months[static_cast<size_t>(tm_time.tm_mon)]}; | 214 | 18.4k | ScopedPadder p(field_value.size(), padinfo_, dest); | 215 | 18.4k | fmt_helper::append_string_view(field_value, dest); | 216 | 18.4k | } |
|
217 | | }; |
218 | | |
219 | | // Date and time representation (Thu Aug 23 15:35:46 2014) |
220 | | template <typename ScopedPadder> |
221 | | class c_formatter final : public flag_formatter { |
222 | | public: |
223 | | explicit c_formatter(padding_info padinfo) |
224 | 129k | : flag_formatter(padinfo) {}spdlog::details::c_formatter<spdlog::details::scoped_padder>::c_formatter(spdlog::details::padding_info) Line | Count | Source | 224 | 68.4k | : flag_formatter(padinfo) {} |
spdlog::details::c_formatter<spdlog::details::null_scoped_padder>::c_formatter(spdlog::details::padding_info) Line | Count | Source | 224 | 60.8k | : flag_formatter(padinfo) {} |
|
225 | | |
226 | 36.2k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
227 | 36.2k | const size_t field_size = 24; |
228 | 36.2k | ScopedPadder p(field_size, padinfo_, dest); |
229 | | |
230 | 36.2k | fmt_helper::append_string_view(days[static_cast<size_t>(tm_time.tm_wday)], dest); |
231 | 36.2k | dest.push_back(' '); |
232 | 36.2k | fmt_helper::append_string_view(months[static_cast<size_t>(tm_time.tm_mon)], dest); |
233 | 36.2k | dest.push_back(' '); |
234 | 36.2k | fmt_helper::append_int(tm_time.tm_mday, dest); |
235 | 36.2k | dest.push_back(' '); |
236 | | // time |
237 | | |
238 | 36.2k | fmt_helper::pad2(tm_time.tm_hour, dest); |
239 | 36.2k | dest.push_back(':'); |
240 | 36.2k | fmt_helper::pad2(tm_time.tm_min, dest); |
241 | 36.2k | dest.push_back(':'); |
242 | 36.2k | fmt_helper::pad2(tm_time.tm_sec, dest); |
243 | 36.2k | dest.push_back(' '); |
244 | 36.2k | fmt_helper::append_int(tm_time.tm_year + 1900, dest); |
245 | 36.2k | } spdlog::details::c_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 226 | 20.4k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 227 | 20.4k | const size_t field_size = 24; | 228 | 20.4k | ScopedPadder p(field_size, padinfo_, dest); | 229 | | | 230 | 20.4k | fmt_helper::append_string_view(days[static_cast<size_t>(tm_time.tm_wday)], dest); | 231 | 20.4k | dest.push_back(' '); | 232 | 20.4k | fmt_helper::append_string_view(months[static_cast<size_t>(tm_time.tm_mon)], dest); | 233 | 20.4k | dest.push_back(' '); | 234 | 20.4k | fmt_helper::append_int(tm_time.tm_mday, dest); | 235 | 20.4k | dest.push_back(' '); | 236 | | // time | 237 | | | 238 | 20.4k | fmt_helper::pad2(tm_time.tm_hour, dest); | 239 | 20.4k | dest.push_back(':'); | 240 | 20.4k | fmt_helper::pad2(tm_time.tm_min, dest); | 241 | 20.4k | dest.push_back(':'); | 242 | 20.4k | fmt_helper::pad2(tm_time.tm_sec, dest); | 243 | 20.4k | dest.push_back(' '); | 244 | 20.4k | fmt_helper::append_int(tm_time.tm_year + 1900, dest); | 245 | 20.4k | } |
spdlog::details::c_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 226 | 15.8k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 227 | 15.8k | const size_t field_size = 24; | 228 | 15.8k | ScopedPadder p(field_size, padinfo_, dest); | 229 | | | 230 | 15.8k | fmt_helper::append_string_view(days[static_cast<size_t>(tm_time.tm_wday)], dest); | 231 | 15.8k | dest.push_back(' '); | 232 | 15.8k | fmt_helper::append_string_view(months[static_cast<size_t>(tm_time.tm_mon)], dest); | 233 | 15.8k | dest.push_back(' '); | 234 | 15.8k | fmt_helper::append_int(tm_time.tm_mday, dest); | 235 | 15.8k | dest.push_back(' '); | 236 | | // time | 237 | | | 238 | 15.8k | fmt_helper::pad2(tm_time.tm_hour, dest); | 239 | 15.8k | dest.push_back(':'); | 240 | 15.8k | fmt_helper::pad2(tm_time.tm_min, dest); | 241 | 15.8k | dest.push_back(':'); | 242 | 15.8k | fmt_helper::pad2(tm_time.tm_sec, dest); | 243 | 15.8k | dest.push_back(' '); | 244 | 15.8k | fmt_helper::append_int(tm_time.tm_year + 1900, dest); | 245 | 15.8k | } |
|
246 | | }; |
247 | | |
248 | | // year - 2 digit |
249 | | template <typename ScopedPadder> |
250 | | class C_formatter final : public flag_formatter { |
251 | | public: |
252 | | explicit C_formatter(padding_info padinfo) |
253 | 45.1k | : flag_formatter(padinfo) {}spdlog::details::C_formatter<spdlog::details::scoped_padder>::C_formatter(spdlog::details::padding_info) Line | Count | Source | 253 | 16.1k | : flag_formatter(padinfo) {} |
spdlog::details::C_formatter<spdlog::details::null_scoped_padder>::C_formatter(spdlog::details::padding_info) Line | Count | Source | 253 | 29.0k | : flag_formatter(padinfo) {} |
|
254 | | |
255 | 9.25k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
256 | 9.25k | const size_t field_size = 2; |
257 | 9.25k | ScopedPadder p(field_size, padinfo_, dest); |
258 | 9.25k | fmt_helper::pad2(tm_time.tm_year % 100, dest); |
259 | 9.25k | } spdlog::details::C_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 255 | 2.27k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 256 | 2.27k | const size_t field_size = 2; | 257 | 2.27k | ScopedPadder p(field_size, padinfo_, dest); | 258 | 2.27k | fmt_helper::pad2(tm_time.tm_year % 100, dest); | 259 | 2.27k | } |
spdlog::details::C_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 255 | 6.98k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 256 | 6.98k | const size_t field_size = 2; | 257 | 6.98k | ScopedPadder p(field_size, padinfo_, dest); | 258 | 6.98k | fmt_helper::pad2(tm_time.tm_year % 100, dest); | 259 | 6.98k | } |
|
260 | | }; |
261 | | |
262 | | // Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01 |
263 | | template <typename ScopedPadder> |
264 | | class D_formatter final : public flag_formatter { |
265 | | public: |
266 | | explicit D_formatter(padding_info padinfo) |
267 | 159k | : flag_formatter(padinfo) {}spdlog::details::D_formatter<spdlog::details::scoped_padder>::D_formatter(spdlog::details::padding_info) Line | Count | Source | 267 | 43.9k | : flag_formatter(padinfo) {} |
spdlog::details::D_formatter<spdlog::details::null_scoped_padder>::D_formatter(spdlog::details::padding_info) Line | Count | Source | 267 | 115k | : flag_formatter(padinfo) {} |
|
268 | | |
269 | 34.2k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
270 | 34.2k | const size_t field_size = 8; |
271 | 34.2k | ScopedPadder p(field_size, padinfo_, dest); |
272 | | |
273 | 34.2k | fmt_helper::pad2(tm_time.tm_mon + 1, dest); |
274 | 34.2k | dest.push_back('/'); |
275 | 34.2k | fmt_helper::pad2(tm_time.tm_mday, dest); |
276 | 34.2k | dest.push_back('/'); |
277 | 34.2k | fmt_helper::pad2(tm_time.tm_year % 100, dest); |
278 | 34.2k | } spdlog::details::D_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 269 | 6.82k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 270 | 6.82k | const size_t field_size = 8; | 271 | 6.82k | ScopedPadder p(field_size, padinfo_, dest); | 272 | | | 273 | 6.82k | fmt_helper::pad2(tm_time.tm_mon + 1, dest); | 274 | 6.82k | dest.push_back('/'); | 275 | 6.82k | fmt_helper::pad2(tm_time.tm_mday, dest); | 276 | 6.82k | dest.push_back('/'); | 277 | 6.82k | fmt_helper::pad2(tm_time.tm_year % 100, dest); | 278 | 6.82k | } |
spdlog::details::D_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 269 | 27.4k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 270 | 27.4k | const size_t field_size = 8; | 271 | 27.4k | ScopedPadder p(field_size, padinfo_, dest); | 272 | | | 273 | 27.4k | fmt_helper::pad2(tm_time.tm_mon + 1, dest); | 274 | 27.4k | dest.push_back('/'); | 275 | 27.4k | fmt_helper::pad2(tm_time.tm_mday, dest); | 276 | 27.4k | dest.push_back('/'); | 277 | 27.4k | fmt_helper::pad2(tm_time.tm_year % 100, dest); | 278 | 27.4k | } |
|
279 | | }; |
280 | | |
281 | | // year - 4 digit |
282 | | template <typename ScopedPadder> |
283 | | class Y_formatter final : public flag_formatter { |
284 | | public: |
285 | | explicit Y_formatter(padding_info padinfo) |
286 | 68.1k | : flag_formatter(padinfo) {}spdlog::details::Y_formatter<spdlog::details::scoped_padder>::Y_formatter(spdlog::details::padding_info) Line | Count | Source | 286 | 55.2k | : flag_formatter(padinfo) {} |
spdlog::details::Y_formatter<spdlog::details::null_scoped_padder>::Y_formatter(spdlog::details::padding_info) Line | Count | Source | 286 | 12.9k | : flag_formatter(padinfo) {} |
|
287 | | |
288 | 14.0k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
289 | 14.0k | const size_t field_size = 4; |
290 | 14.0k | ScopedPadder p(field_size, padinfo_, dest); |
291 | 14.0k | fmt_helper::append_int(tm_time.tm_year + 1900, dest); |
292 | 14.0k | } spdlog::details::Y_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 288 | 10.6k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 289 | 10.6k | const size_t field_size = 4; | 290 | 10.6k | ScopedPadder p(field_size, padinfo_, dest); | 291 | 10.6k | fmt_helper::append_int(tm_time.tm_year + 1900, dest); | 292 | 10.6k | } |
spdlog::details::Y_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 288 | 3.44k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 289 | 3.44k | const size_t field_size = 4; | 290 | 3.44k | ScopedPadder p(field_size, padinfo_, dest); | 291 | 3.44k | fmt_helper::append_int(tm_time.tm_year + 1900, dest); | 292 | 3.44k | } |
|
293 | | }; |
294 | | |
295 | | // month 1-12 |
296 | | template <typename ScopedPadder> |
297 | | class m_formatter final : public flag_formatter { |
298 | | public: |
299 | | explicit m_formatter(padding_info padinfo) |
300 | 124k | : flag_formatter(padinfo) {}spdlog::details::m_formatter<spdlog::details::scoped_padder>::m_formatter(spdlog::details::padding_info) Line | Count | Source | 300 | 104k | : flag_formatter(padinfo) {} |
spdlog::details::m_formatter<spdlog::details::null_scoped_padder>::m_formatter(spdlog::details::padding_info) Line | Count | Source | 300 | 19.8k | : flag_formatter(padinfo) {} |
|
301 | | |
302 | 11.3k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
303 | 11.3k | const size_t field_size = 2; |
304 | 11.3k | ScopedPadder p(field_size, padinfo_, dest); |
305 | 11.3k | fmt_helper::pad2(tm_time.tm_mon + 1, dest); |
306 | 11.3k | } spdlog::details::m_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 302 | 7.73k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 303 | 7.73k | const size_t field_size = 2; | 304 | 7.73k | ScopedPadder p(field_size, padinfo_, dest); | 305 | 7.73k | fmt_helper::pad2(tm_time.tm_mon + 1, dest); | 306 | 7.73k | } |
spdlog::details::m_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 302 | 3.56k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 303 | 3.56k | const size_t field_size = 2; | 304 | 3.56k | ScopedPadder p(field_size, padinfo_, dest); | 305 | 3.56k | fmt_helper::pad2(tm_time.tm_mon + 1, dest); | 306 | 3.56k | } |
|
307 | | }; |
308 | | |
309 | | // day of month 1-31 |
310 | | template <typename ScopedPadder> |
311 | | class d_formatter final : public flag_formatter { |
312 | | public: |
313 | | explicit d_formatter(padding_info padinfo) |
314 | 141k | : flag_formatter(padinfo) {}spdlog::details::d_formatter<spdlog::details::scoped_padder>::d_formatter(spdlog::details::padding_info) Line | Count | Source | 314 | 60.6k | : flag_formatter(padinfo) {} |
spdlog::details::d_formatter<spdlog::details::null_scoped_padder>::d_formatter(spdlog::details::padding_info) Line | Count | Source | 314 | 80.7k | : flag_formatter(padinfo) {} |
|
315 | | |
316 | 22.5k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
317 | 22.5k | const size_t field_size = 2; |
318 | 22.5k | ScopedPadder p(field_size, padinfo_, dest); |
319 | 22.5k | fmt_helper::pad2(tm_time.tm_mday, dest); |
320 | 22.5k | } spdlog::details::d_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 316 | 12.4k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 317 | 12.4k | const size_t field_size = 2; | 318 | 12.4k | ScopedPadder p(field_size, padinfo_, dest); | 319 | 12.4k | fmt_helper::pad2(tm_time.tm_mday, dest); | 320 | 12.4k | } |
spdlog::details::d_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 316 | 10.1k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 317 | 10.1k | const size_t field_size = 2; | 318 | 10.1k | ScopedPadder p(field_size, padinfo_, dest); | 319 | 10.1k | fmt_helper::pad2(tm_time.tm_mday, dest); | 320 | 10.1k | } |
|
321 | | }; |
322 | | |
323 | | // hours in 24 format 0-23 |
324 | | template <typename ScopedPadder> |
325 | | class H_formatter final : public flag_formatter { |
326 | | public: |
327 | | explicit H_formatter(padding_info padinfo) |
328 | 406k | : flag_formatter(padinfo) {}spdlog::details::H_formatter<spdlog::details::scoped_padder>::H_formatter(spdlog::details::padding_info) Line | Count | Source | 328 | 43.2k | : flag_formatter(padinfo) {} |
spdlog::details::H_formatter<spdlog::details::null_scoped_padder>::H_formatter(spdlog::details::padding_info) Line | Count | Source | 328 | 363k | : flag_formatter(padinfo) {} |
|
329 | | |
330 | 24.0k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
331 | 24.0k | const size_t field_size = 2; |
332 | 24.0k | ScopedPadder p(field_size, padinfo_, dest); |
333 | 24.0k | fmt_helper::pad2(tm_time.tm_hour, dest); |
334 | 24.0k | } spdlog::details::H_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 330 | 12.6k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 331 | 12.6k | const size_t field_size = 2; | 332 | 12.6k | ScopedPadder p(field_size, padinfo_, dest); | 333 | 12.6k | fmt_helper::pad2(tm_time.tm_hour, dest); | 334 | 12.6k | } |
spdlog::details::H_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 330 | 11.4k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 331 | 11.4k | const size_t field_size = 2; | 332 | 11.4k | ScopedPadder p(field_size, padinfo_, dest); | 333 | 11.4k | fmt_helper::pad2(tm_time.tm_hour, dest); | 334 | 11.4k | } |
|
335 | | }; |
336 | | |
337 | | // hours in 12 format 1-12 |
338 | | template <typename ScopedPadder> |
339 | | class I_formatter final : public flag_formatter { |
340 | | public: |
341 | | explicit I_formatter(padding_info padinfo) |
342 | 88.8k | : flag_formatter(padinfo) {}spdlog::details::I_formatter<spdlog::details::scoped_padder>::I_formatter(spdlog::details::padding_info) Line | Count | Source | 342 | 70.0k | : flag_formatter(padinfo) {} |
spdlog::details::I_formatter<spdlog::details::null_scoped_padder>::I_formatter(spdlog::details::padding_info) Line | Count | Source | 342 | 18.8k | : flag_formatter(padinfo) {} |
|
343 | | |
344 | 14.2k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
345 | 14.2k | const size_t field_size = 2; |
346 | 14.2k | ScopedPadder p(field_size, padinfo_, dest); |
347 | 14.2k | fmt_helper::pad2(to12h(tm_time), dest); |
348 | 14.2k | } spdlog::details::I_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 344 | 11.6k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 345 | 11.6k | const size_t field_size = 2; | 346 | 11.6k | ScopedPadder p(field_size, padinfo_, dest); | 347 | 11.6k | fmt_helper::pad2(to12h(tm_time), dest); | 348 | 11.6k | } |
spdlog::details::I_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 344 | 2.68k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 345 | 2.68k | const size_t field_size = 2; | 346 | 2.68k | ScopedPadder p(field_size, padinfo_, dest); | 347 | 2.68k | fmt_helper::pad2(to12h(tm_time), dest); | 348 | 2.68k | } |
|
349 | | }; |
350 | | |
351 | | // minutes 0-59 |
352 | | template <typename ScopedPadder> |
353 | | class M_formatter final : public flag_formatter { |
354 | | public: |
355 | | explicit M_formatter(padding_info padinfo) |
356 | 569k | : flag_formatter(padinfo) {}spdlog::details::M_formatter<spdlog::details::scoped_padder>::M_formatter(spdlog::details::padding_info) Line | Count | Source | 356 | 154k | : flag_formatter(padinfo) {} |
spdlog::details::M_formatter<spdlog::details::null_scoped_padder>::M_formatter(spdlog::details::padding_info) Line | Count | Source | 356 | 414k | : flag_formatter(padinfo) {} |
|
357 | | |
358 | 33.6k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
359 | 33.6k | const size_t field_size = 2; |
360 | 33.6k | ScopedPadder p(field_size, padinfo_, dest); |
361 | 33.6k | fmt_helper::pad2(tm_time.tm_min, dest); |
362 | 33.6k | } spdlog::details::M_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 358 | 10.9k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 359 | 10.9k | const size_t field_size = 2; | 360 | 10.9k | ScopedPadder p(field_size, padinfo_, dest); | 361 | 10.9k | fmt_helper::pad2(tm_time.tm_min, dest); | 362 | 10.9k | } |
spdlog::details::M_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 358 | 22.6k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 359 | 22.6k | const size_t field_size = 2; | 360 | 22.6k | ScopedPadder p(field_size, padinfo_, dest); | 361 | 22.6k | fmt_helper::pad2(tm_time.tm_min, dest); | 362 | 22.6k | } |
|
363 | | }; |
364 | | |
365 | | // seconds 0-59 |
366 | | template <typename ScopedPadder> |
367 | | class S_formatter final : public flag_formatter { |
368 | | public: |
369 | | explicit S_formatter(padding_info padinfo) |
370 | 365k | : flag_formatter(padinfo) {}spdlog::details::S_formatter<spdlog::details::scoped_padder>::S_formatter(spdlog::details::padding_info) Line | Count | Source | 370 | 8.46k | : flag_formatter(padinfo) {} |
spdlog::details::S_formatter<spdlog::details::null_scoped_padder>::S_formatter(spdlog::details::padding_info) Line | Count | Source | 370 | 357k | : flag_formatter(padinfo) {} |
|
371 | | |
372 | 10.6k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
373 | 10.6k | const size_t field_size = 2; |
374 | 10.6k | ScopedPadder p(field_size, padinfo_, dest); |
375 | 10.6k | fmt_helper::pad2(tm_time.tm_sec, dest); |
376 | 10.6k | } spdlog::details::S_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 372 | 2.03k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 373 | 2.03k | const size_t field_size = 2; | 374 | 2.03k | ScopedPadder p(field_size, padinfo_, dest); | 375 | 2.03k | fmt_helper::pad2(tm_time.tm_sec, dest); | 376 | 2.03k | } |
spdlog::details::S_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 372 | 8.60k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 373 | 8.60k | const size_t field_size = 2; | 374 | 8.60k | ScopedPadder p(field_size, padinfo_, dest); | 375 | 8.60k | fmt_helper::pad2(tm_time.tm_sec, dest); | 376 | 8.60k | } |
|
377 | | }; |
378 | | |
379 | | // milliseconds |
380 | | template <typename ScopedPadder> |
381 | | class e_formatter final : public flag_formatter { |
382 | | public: |
383 | | explicit e_formatter(padding_info padinfo) |
384 | 119k | : flag_formatter(padinfo) {}spdlog::details::e_formatter<spdlog::details::scoped_padder>::e_formatter(spdlog::details::padding_info) Line | Count | Source | 384 | 53.1k | : flag_formatter(padinfo) {} |
spdlog::details::e_formatter<spdlog::details::null_scoped_padder>::e_formatter(spdlog::details::padding_info) Line | Count | Source | 384 | 66.0k | : flag_formatter(padinfo) {} |
|
385 | | |
386 | 27.3k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
387 | 27.3k | auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time); |
388 | 27.3k | const size_t field_size = 3; |
389 | 27.3k | ScopedPadder p(field_size, padinfo_, dest); |
390 | 27.3k | fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest); |
391 | 27.3k | } spdlog::details::e_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 386 | 11.7k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 387 | 11.7k | auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time); | 388 | 11.7k | const size_t field_size = 3; | 389 | 11.7k | ScopedPadder p(field_size, padinfo_, dest); | 390 | 11.7k | fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest); | 391 | 11.7k | } |
spdlog::details::e_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 386 | 15.5k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 387 | 15.5k | auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time); | 388 | 15.5k | const size_t field_size = 3; | 389 | 15.5k | ScopedPadder p(field_size, padinfo_, dest); | 390 | 15.5k | fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest); | 391 | 15.5k | } |
|
392 | | }; |
393 | | |
394 | | // microseconds |
395 | | template <typename ScopedPadder> |
396 | | class f_formatter final : public flag_formatter { |
397 | | public: |
398 | | explicit f_formatter(padding_info padinfo) |
399 | 270k | : flag_formatter(padinfo) {}spdlog::details::f_formatter<spdlog::details::scoped_padder>::f_formatter(spdlog::details::padding_info) Line | Count | Source | 399 | 68.2k | : flag_formatter(padinfo) {} |
spdlog::details::f_formatter<spdlog::details::null_scoped_padder>::f_formatter(spdlog::details::padding_info) Line | Count | Source | 399 | 201k | : flag_formatter(padinfo) {} |
|
400 | | |
401 | 21.3k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
402 | 21.3k | auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time); |
403 | | |
404 | 21.3k | const size_t field_size = 6; |
405 | 21.3k | ScopedPadder p(field_size, padinfo_, dest); |
406 | 21.3k | fmt_helper::pad6(static_cast<size_t>(micros.count()), dest); |
407 | 21.3k | } spdlog::details::f_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 401 | 9.10k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 402 | 9.10k | auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time); | 403 | | | 404 | 9.10k | const size_t field_size = 6; | 405 | 9.10k | ScopedPadder p(field_size, padinfo_, dest); | 406 | 9.10k | fmt_helper::pad6(static_cast<size_t>(micros.count()), dest); | 407 | 9.10k | } |
spdlog::details::f_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 401 | 12.2k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 402 | 12.2k | auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time); | 403 | | | 404 | 12.2k | const size_t field_size = 6; | 405 | 12.2k | ScopedPadder p(field_size, padinfo_, dest); | 406 | 12.2k | fmt_helper::pad6(static_cast<size_t>(micros.count()), dest); | 407 | 12.2k | } |
|
408 | | }; |
409 | | |
410 | | // nanoseconds |
411 | | template <typename ScopedPadder> |
412 | | class F_formatter final : public flag_formatter { |
413 | | public: |
414 | | explicit F_formatter(padding_info padinfo) |
415 | 344k | : flag_formatter(padinfo) {}spdlog::details::F_formatter<spdlog::details::scoped_padder>::F_formatter(spdlog::details::padding_info) Line | Count | Source | 415 | 308k | : flag_formatter(padinfo) {} |
spdlog::details::F_formatter<spdlog::details::null_scoped_padder>::F_formatter(spdlog::details::padding_info) Line | Count | Source | 415 | 36.0k | : flag_formatter(padinfo) {} |
|
416 | | |
417 | 79.7k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
418 | 79.7k | auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time); |
419 | 79.7k | const size_t field_size = 9; |
420 | 79.7k | ScopedPadder p(field_size, padinfo_, dest); |
421 | 79.7k | fmt_helper::pad9(static_cast<size_t>(ns.count()), dest); |
422 | 79.7k | } spdlog::details::F_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 417 | 70.0k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 418 | 70.0k | auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time); | 419 | 70.0k | const size_t field_size = 9; | 420 | 70.0k | ScopedPadder p(field_size, padinfo_, dest); | 421 | 70.0k | fmt_helper::pad9(static_cast<size_t>(ns.count()), dest); | 422 | 70.0k | } |
spdlog::details::F_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 417 | 9.72k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 418 | 9.72k | auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time); | 419 | 9.72k | const size_t field_size = 9; | 420 | 9.72k | ScopedPadder p(field_size, padinfo_, dest); | 421 | 9.72k | fmt_helper::pad9(static_cast<size_t>(ns.count()), dest); | 422 | 9.72k | } |
|
423 | | }; |
424 | | |
425 | | // seconds since epoch |
426 | | template <typename ScopedPadder> |
427 | | class E_formatter final : public flag_formatter { |
428 | | public: |
429 | | explicit E_formatter(padding_info padinfo) |
430 | 134k | : flag_formatter(padinfo) {}spdlog::details::E_formatter<spdlog::details::scoped_padder>::E_formatter(spdlog::details::padding_info) Line | Count | Source | 430 | 108k | : flag_formatter(padinfo) {} |
spdlog::details::E_formatter<spdlog::details::null_scoped_padder>::E_formatter(spdlog::details::padding_info) Line | Count | Source | 430 | 26.2k | : flag_formatter(padinfo) {} |
|
431 | | |
432 | 12.7k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
433 | 12.7k | const size_t field_size = 10; |
434 | 12.7k | ScopedPadder p(field_size, padinfo_, dest); |
435 | 12.7k | auto duration = msg.time.time_since_epoch(); |
436 | 12.7k | auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count(); |
437 | 12.7k | fmt_helper::append_int(seconds, dest); |
438 | 12.7k | } spdlog::details::E_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 432 | 8.05k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 433 | 8.05k | const size_t field_size = 10; | 434 | 8.05k | ScopedPadder p(field_size, padinfo_, dest); | 435 | 8.05k | auto duration = msg.time.time_since_epoch(); | 436 | 8.05k | auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count(); | 437 | 8.05k | fmt_helper::append_int(seconds, dest); | 438 | 8.05k | } |
spdlog::details::E_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 432 | 4.69k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 433 | 4.69k | const size_t field_size = 10; | 434 | 4.69k | ScopedPadder p(field_size, padinfo_, dest); | 435 | 4.69k | auto duration = msg.time.time_since_epoch(); | 436 | 4.69k | auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count(); | 437 | 4.69k | fmt_helper::append_int(seconds, dest); | 438 | 4.69k | } |
|
439 | | }; |
440 | | |
441 | | // AM/PM |
442 | | template <typename ScopedPadder> |
443 | | class p_formatter final : public flag_formatter { |
444 | | public: |
445 | | explicit p_formatter(padding_info padinfo) |
446 | 73.1k | : flag_formatter(padinfo) {}spdlog::details::p_formatter<spdlog::details::scoped_padder>::p_formatter(spdlog::details::padding_info) Line | Count | Source | 446 | 50.3k | : flag_formatter(padinfo) {} |
spdlog::details::p_formatter<spdlog::details::null_scoped_padder>::p_formatter(spdlog::details::padding_info) Line | Count | Source | 446 | 22.8k | : flag_formatter(padinfo) {} |
|
447 | | |
448 | 13.5k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
449 | 13.5k | const size_t field_size = 2; |
450 | 13.5k | ScopedPadder p(field_size, padinfo_, dest); |
451 | 13.5k | fmt_helper::append_string_view(ampm(tm_time), dest); |
452 | 13.5k | } spdlog::details::p_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 448 | 6.87k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 449 | 6.87k | const size_t field_size = 2; | 450 | 6.87k | ScopedPadder p(field_size, padinfo_, dest); | 451 | 6.87k | fmt_helper::append_string_view(ampm(tm_time), dest); | 452 | 6.87k | } |
spdlog::details::p_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 448 | 6.65k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 449 | 6.65k | const size_t field_size = 2; | 450 | 6.65k | ScopedPadder p(field_size, padinfo_, dest); | 451 | 6.65k | fmt_helper::append_string_view(ampm(tm_time), dest); | 452 | 6.65k | } |
|
453 | | }; |
454 | | |
455 | | // 12 hour clock 02:55:02 pm |
456 | | template <typename ScopedPadder> |
457 | | class r_formatter final : public flag_formatter { |
458 | | public: |
459 | | explicit r_formatter(padding_info padinfo) |
460 | 140k | : flag_formatter(padinfo) {}spdlog::details::r_formatter<spdlog::details::scoped_padder>::r_formatter(spdlog::details::padding_info) Line | Count | Source | 460 | 64.6k | : flag_formatter(padinfo) {} |
spdlog::details::r_formatter<spdlog::details::null_scoped_padder>::r_formatter(spdlog::details::padding_info) Line | Count | Source | 460 | 75.6k | : flag_formatter(padinfo) {} |
|
461 | | |
462 | 18.1k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
463 | 18.1k | const size_t field_size = 11; |
464 | 18.1k | ScopedPadder p(field_size, padinfo_, dest); |
465 | | |
466 | 18.1k | fmt_helper::pad2(to12h(tm_time), dest); |
467 | 18.1k | dest.push_back(':'); |
468 | 18.1k | fmt_helper::pad2(tm_time.tm_min, dest); |
469 | 18.1k | dest.push_back(':'); |
470 | 18.1k | fmt_helper::pad2(tm_time.tm_sec, dest); |
471 | 18.1k | dest.push_back(' '); |
472 | 18.1k | fmt_helper::append_string_view(ampm(tm_time), dest); |
473 | 18.1k | } spdlog::details::r_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 462 | 2.86k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 463 | 2.86k | const size_t field_size = 11; | 464 | 2.86k | ScopedPadder p(field_size, padinfo_, dest); | 465 | | | 466 | 2.86k | fmt_helper::pad2(to12h(tm_time), dest); | 467 | 2.86k | dest.push_back(':'); | 468 | 2.86k | fmt_helper::pad2(tm_time.tm_min, dest); | 469 | 2.86k | dest.push_back(':'); | 470 | 2.86k | fmt_helper::pad2(tm_time.tm_sec, dest); | 471 | 2.86k | dest.push_back(' '); | 472 | 2.86k | fmt_helper::append_string_view(ampm(tm_time), dest); | 473 | 2.86k | } |
spdlog::details::r_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 462 | 15.2k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 463 | 15.2k | const size_t field_size = 11; | 464 | 15.2k | ScopedPadder p(field_size, padinfo_, dest); | 465 | | | 466 | 15.2k | fmt_helper::pad2(to12h(tm_time), dest); | 467 | 15.2k | dest.push_back(':'); | 468 | 15.2k | fmt_helper::pad2(tm_time.tm_min, dest); | 469 | 15.2k | dest.push_back(':'); | 470 | 15.2k | fmt_helper::pad2(tm_time.tm_sec, dest); | 471 | 15.2k | dest.push_back(' '); | 472 | 15.2k | fmt_helper::append_string_view(ampm(tm_time), dest); | 473 | 15.2k | } |
|
474 | | }; |
475 | | |
476 | | // 24-hour HH:MM time, equivalent to %H:%M |
477 | | template <typename ScopedPadder> |
478 | | class R_formatter final : public flag_formatter { |
479 | | public: |
480 | | explicit R_formatter(padding_info padinfo) |
481 | 157k | : flag_formatter(padinfo) {}spdlog::details::R_formatter<spdlog::details::scoped_padder>::R_formatter(spdlog::details::padding_info) Line | Count | Source | 481 | 17.7k | : flag_formatter(padinfo) {} |
spdlog::details::R_formatter<spdlog::details::null_scoped_padder>::R_formatter(spdlog::details::padding_info) Line | Count | Source | 481 | 140k | : flag_formatter(padinfo) {} |
|
482 | | |
483 | 48.4k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
484 | 48.4k | const size_t field_size = 5; |
485 | 48.4k | ScopedPadder p(field_size, padinfo_, dest); |
486 | | |
487 | 48.4k | fmt_helper::pad2(tm_time.tm_hour, dest); |
488 | 48.4k | dest.push_back(':'); |
489 | 48.4k | fmt_helper::pad2(tm_time.tm_min, dest); |
490 | 48.4k | } spdlog::details::R_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 483 | 3.35k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 484 | 3.35k | const size_t field_size = 5; | 485 | 3.35k | ScopedPadder p(field_size, padinfo_, dest); | 486 | | | 487 | 3.35k | fmt_helper::pad2(tm_time.tm_hour, dest); | 488 | 3.35k | dest.push_back(':'); | 489 | 3.35k | fmt_helper::pad2(tm_time.tm_min, dest); | 490 | 3.35k | } |
spdlog::details::R_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 483 | 45.0k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 484 | 45.0k | const size_t field_size = 5; | 485 | 45.0k | ScopedPadder p(field_size, padinfo_, dest); | 486 | | | 487 | 45.0k | fmt_helper::pad2(tm_time.tm_hour, dest); | 488 | 45.0k | dest.push_back(':'); | 489 | 45.0k | fmt_helper::pad2(tm_time.tm_min, dest); | 490 | 45.0k | } |
|
491 | | }; |
492 | | |
493 | | // ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S |
494 | | template <typename ScopedPadder> |
495 | | class T_formatter final : public flag_formatter { |
496 | | public: |
497 | | explicit T_formatter(padding_info padinfo) |
498 | 161k | : flag_formatter(padinfo) {}spdlog::details::T_formatter<spdlog::details::scoped_padder>::T_formatter(spdlog::details::padding_info) Line | Count | Source | 498 | 62.5k | : flag_formatter(padinfo) {} |
spdlog::details::T_formatter<spdlog::details::null_scoped_padder>::T_formatter(spdlog::details::padding_info) Line | Count | Source | 498 | 98.8k | : flag_formatter(padinfo) {} |
|
499 | | |
500 | 31.0k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { |
501 | 31.0k | const size_t field_size = 8; |
502 | 31.0k | ScopedPadder p(field_size, padinfo_, dest); |
503 | | |
504 | 31.0k | fmt_helper::pad2(tm_time.tm_hour, dest); |
505 | 31.0k | dest.push_back(':'); |
506 | 31.0k | fmt_helper::pad2(tm_time.tm_min, dest); |
507 | 31.0k | dest.push_back(':'); |
508 | 31.0k | fmt_helper::pad2(tm_time.tm_sec, dest); |
509 | 31.0k | } spdlog::details::T_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 500 | 8.09k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 501 | 8.09k | const size_t field_size = 8; | 502 | 8.09k | ScopedPadder p(field_size, padinfo_, dest); | 503 | | | 504 | 8.09k | fmt_helper::pad2(tm_time.tm_hour, dest); | 505 | 8.09k | dest.push_back(':'); | 506 | 8.09k | fmt_helper::pad2(tm_time.tm_min, dest); | 507 | 8.09k | dest.push_back(':'); | 508 | 8.09k | fmt_helper::pad2(tm_time.tm_sec, dest); | 509 | 8.09k | } |
spdlog::details::T_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 500 | 23.0k | void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { | 501 | 23.0k | const size_t field_size = 8; | 502 | 23.0k | ScopedPadder p(field_size, padinfo_, dest); | 503 | | | 504 | 23.0k | fmt_helper::pad2(tm_time.tm_hour, dest); | 505 | 23.0k | dest.push_back(':'); | 506 | 23.0k | fmt_helper::pad2(tm_time.tm_min, dest); | 507 | 23.0k | dest.push_back(':'); | 508 | 23.0k | fmt_helper::pad2(tm_time.tm_sec, dest); | 509 | 23.0k | } |
|
510 | | }; |
511 | | |
512 | | // ISO 8601 offset from UTC in timezone (+-HH:MM) |
513 | | template <typename ScopedPadder> |
514 | | class z_formatter final : public flag_formatter { |
515 | | public: |
516 | | explicit z_formatter(padding_info padinfo) |
517 | 506k | : flag_formatter(padinfo) {}spdlog::details::z_formatter<spdlog::details::scoped_padder>::z_formatter(spdlog::details::padding_info) Line | Count | Source | 517 | 98.4k | : flag_formatter(padinfo) {} |
spdlog::details::z_formatter<spdlog::details::null_scoped_padder>::z_formatter(spdlog::details::padding_info) Line | Count | Source | 517 | 408k | : flag_formatter(padinfo) {} |
|
518 | | |
519 | | z_formatter() = default; |
520 | | z_formatter(const z_formatter &) = delete; |
521 | | z_formatter &operator=(const z_formatter &) = delete; |
522 | | |
523 | 23.4k | void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { |
524 | 23.4k | const size_t field_size = 6; |
525 | 23.4k | ScopedPadder p(field_size, padinfo_, dest); |
526 | | |
527 | 23.4k | auto total_minutes = get_cached_offset(msg, tm_time); |
528 | 23.4k | bool is_negative = total_minutes < 0; |
529 | 23.4k | if (is_negative) { |
530 | 0 | total_minutes = -total_minutes; |
531 | 0 | dest.push_back('-'); |
532 | 23.4k | } else { |
533 | 23.4k | dest.push_back('+'); |
534 | 23.4k | } |
535 | | |
536 | 23.4k | fmt_helper::pad2(total_minutes / 60, dest); // hours |
537 | 23.4k | dest.push_back(':'); |
538 | 23.4k | fmt_helper::pad2(total_minutes % 60, dest); // minutes |
539 | 23.4k | } spdlog::details::z_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 523 | 18.1k | void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { | 524 | 18.1k | const size_t field_size = 6; | 525 | 18.1k | ScopedPadder p(field_size, padinfo_, dest); | 526 | | | 527 | 18.1k | auto total_minutes = get_cached_offset(msg, tm_time); | 528 | 18.1k | bool is_negative = total_minutes < 0; | 529 | 18.1k | if (is_negative) { | 530 | 0 | total_minutes = -total_minutes; | 531 | 0 | dest.push_back('-'); | 532 | 18.1k | } else { | 533 | 18.1k | dest.push_back('+'); | 534 | 18.1k | } | 535 | | | 536 | 18.1k | fmt_helper::pad2(total_minutes / 60, dest); // hours | 537 | 18.1k | dest.push_back(':'); | 538 | 18.1k | fmt_helper::pad2(total_minutes % 60, dest); // minutes | 539 | 18.1k | } |
spdlog::details::z_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 523 | 5.32k | void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { | 524 | 5.32k | const size_t field_size = 6; | 525 | 5.32k | ScopedPadder p(field_size, padinfo_, dest); | 526 | | | 527 | 5.32k | auto total_minutes = get_cached_offset(msg, tm_time); | 528 | 5.32k | bool is_negative = total_minutes < 0; | 529 | 5.32k | if (is_negative) { | 530 | 0 | total_minutes = -total_minutes; | 531 | 0 | dest.push_back('-'); | 532 | 5.32k | } else { | 533 | 5.32k | dest.push_back('+'); | 534 | 5.32k | } | 535 | | | 536 | 5.32k | fmt_helper::pad2(total_minutes / 60, dest); // hours | 537 | 5.32k | dest.push_back(':'); | 538 | 5.32k | fmt_helper::pad2(total_minutes % 60, dest); // minutes | 539 | 5.32k | } |
|
540 | | |
541 | | private: |
542 | | log_clock::time_point last_update_{std::chrono::seconds(0)}; |
543 | | int offset_minutes_{0}; |
544 | | |
545 | 23.4k | int get_cached_offset(const log_msg &msg, const std::tm &tm_time) { |
546 | | // refresh every 10 seconds |
547 | 23.4k | if (msg.time - last_update_ >= std::chrono::seconds(10)) { |
548 | 23.4k | offset_minutes_ = os::utc_minutes_offset(tm_time); |
549 | 23.4k | last_update_ = msg.time; |
550 | 23.4k | } |
551 | 23.4k | return offset_minutes_; |
552 | 23.4k | } spdlog::details::z_formatter<spdlog::details::scoped_padder>::get_cached_offset(spdlog::details::log_msg const&, tm const&) Line | Count | Source | 545 | 18.1k | int get_cached_offset(const log_msg &msg, const std::tm &tm_time) { | 546 | | // refresh every 10 seconds | 547 | 18.1k | if (msg.time - last_update_ >= std::chrono::seconds(10)) { | 548 | 18.1k | offset_minutes_ = os::utc_minutes_offset(tm_time); | 549 | 18.1k | last_update_ = msg.time; | 550 | 18.1k | } | 551 | 18.1k | return offset_minutes_; | 552 | 18.1k | } |
spdlog::details::z_formatter<spdlog::details::null_scoped_padder>::get_cached_offset(spdlog::details::log_msg const&, tm const&) Line | Count | Source | 545 | 5.32k | int get_cached_offset(const log_msg &msg, const std::tm &tm_time) { | 546 | | // refresh every 10 seconds | 547 | 5.32k | if (msg.time - last_update_ >= std::chrono::seconds(10)) { | 548 | 5.32k | offset_minutes_ = os::utc_minutes_offset(tm_time); | 549 | 5.32k | last_update_ = msg.time; | 550 | 5.32k | } | 551 | 5.32k | return offset_minutes_; | 552 | 5.32k | } |
|
553 | | }; |
554 | | |
555 | | // Thread id |
556 | | template <typename ScopedPadder> |
557 | | class t_formatter final : public flag_formatter { |
558 | | public: |
559 | | explicit t_formatter(padding_info padinfo) |
560 | 164k | : flag_formatter(padinfo) {}spdlog::details::t_formatter<spdlog::details::scoped_padder>::t_formatter(spdlog::details::padding_info) Line | Count | Source | 560 | 59.2k | : flag_formatter(padinfo) {} |
spdlog::details::t_formatter<spdlog::details::null_scoped_padder>::t_formatter(spdlog::details::padding_info) Line | Count | Source | 560 | 105k | : flag_formatter(padinfo) {} |
|
561 | | |
562 | 14.1k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
563 | 14.1k | const auto field_size = ScopedPadder::count_digits(msg.thread_id); |
564 | 14.1k | ScopedPadder p(field_size, padinfo_, dest); |
565 | 14.1k | fmt_helper::append_int(msg.thread_id, dest); |
566 | 14.1k | } spdlog::details::t_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 562 | 4.32k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 563 | 4.32k | const auto field_size = ScopedPadder::count_digits(msg.thread_id); | 564 | 4.32k | ScopedPadder p(field_size, padinfo_, dest); | 565 | 4.32k | fmt_helper::append_int(msg.thread_id, dest); | 566 | 4.32k | } |
spdlog::details::t_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 562 | 9.84k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 563 | 9.84k | const auto field_size = ScopedPadder::count_digits(msg.thread_id); | 564 | 9.84k | ScopedPadder p(field_size, padinfo_, dest); | 565 | 9.84k | fmt_helper::append_int(msg.thread_id, dest); | 566 | 9.84k | } |
|
567 | | }; |
568 | | |
569 | | // Current pid |
570 | | template <typename ScopedPadder> |
571 | | class pid_formatter final : public flag_formatter { |
572 | | public: |
573 | | explicit pid_formatter(padding_info padinfo) |
574 | 193k | : flag_formatter(padinfo) {}spdlog::details::pid_formatter<spdlog::details::scoped_padder>::pid_formatter(spdlog::details::padding_info) Line | Count | Source | 574 | 94.9k | : flag_formatter(padinfo) {} |
spdlog::details::pid_formatter<spdlog::details::null_scoped_padder>::pid_formatter(spdlog::details::padding_info) Line | Count | Source | 574 | 98.2k | : flag_formatter(padinfo) {} |
|
575 | | |
576 | 25.2k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { |
577 | 25.2k | const auto pid = static_cast<uint32_t>(details::os::pid()); |
578 | 25.2k | auto field_size = ScopedPadder::count_digits(pid); |
579 | 25.2k | ScopedPadder p(field_size, padinfo_, dest); |
580 | 25.2k | fmt_helper::append_int(pid, dest); |
581 | 25.2k | } spdlog::details::pid_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 576 | 1.59k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { | 577 | 1.59k | const auto pid = static_cast<uint32_t>(details::os::pid()); | 578 | 1.59k | auto field_size = ScopedPadder::count_digits(pid); | 579 | 1.59k | ScopedPadder p(field_size, padinfo_, dest); | 580 | 1.59k | fmt_helper::append_int(pid, dest); | 581 | 1.59k | } |
spdlog::details::pid_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 576 | 23.6k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { | 577 | 23.6k | const auto pid = static_cast<uint32_t>(details::os::pid()); | 578 | 23.6k | auto field_size = ScopedPadder::count_digits(pid); | 579 | 23.6k | ScopedPadder p(field_size, padinfo_, dest); | 580 | 23.6k | fmt_helper::append_int(pid, dest); | 581 | 23.6k | } |
|
582 | | }; |
583 | | |
584 | | template <typename ScopedPadder> |
585 | | class v_formatter final : public flag_formatter { |
586 | | public: |
587 | | explicit v_formatter(padding_info padinfo) |
588 | 47.4k | : flag_formatter(padinfo) {}spdlog::details::v_formatter<spdlog::details::scoped_padder>::v_formatter(spdlog::details::padding_info) Line | Count | Source | 588 | 22.1k | : flag_formatter(padinfo) {} |
spdlog::details::v_formatter<spdlog::details::null_scoped_padder>::v_formatter(spdlog::details::padding_info) Line | Count | Source | 588 | 25.2k | : flag_formatter(padinfo) {} |
|
589 | | |
590 | 10.3k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
591 | 10.3k | ScopedPadder p(msg.payload.size(), padinfo_, dest); |
592 | 10.3k | fmt_helper::append_string_view(msg.payload, dest); |
593 | 10.3k | } spdlog::details::v_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 590 | 2.79k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 591 | 2.79k | ScopedPadder p(msg.payload.size(), padinfo_, dest); | 592 | 2.79k | fmt_helper::append_string_view(msg.payload, dest); | 593 | 2.79k | } |
spdlog::details::v_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 590 | 7.53k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 591 | 7.53k | ScopedPadder p(msg.payload.size(), padinfo_, dest); | 592 | 7.53k | fmt_helper::append_string_view(msg.payload, dest); | 593 | 7.53k | } |
|
594 | | }; |
595 | | |
596 | | class ch_formatter final : public flag_formatter { |
597 | | public: |
598 | | explicit ch_formatter(char ch) |
599 | 933k | : ch_(ch) {} |
600 | | |
601 | 104k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { |
602 | 104k | dest.push_back(ch_); |
603 | 104k | } |
604 | | |
605 | | private: |
606 | | char ch_; |
607 | | }; |
608 | | |
609 | | // aggregate user chars to display as is |
610 | | class aggregate_formatter final : public flag_formatter { |
611 | | public: |
612 | 5.71M | aggregate_formatter() = default; |
613 | | |
614 | 104M | void add_ch(char ch) { str_ += ch; } |
615 | 832k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { |
616 | 832k | fmt_helper::append_string_view(str_, dest); |
617 | 832k | } |
618 | | |
619 | | private: |
620 | | std::string str_; |
621 | | }; |
622 | | |
623 | | // mark the color range. expect it to be in the form of "%^colored text%$" |
624 | | class color_start_formatter final : public flag_formatter { |
625 | | public: |
626 | | explicit color_start_formatter(padding_info padinfo) |
627 | 70.3k | : flag_formatter(padinfo) {} |
628 | | |
629 | 10.5k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
630 | 10.5k | msg.color_range_start = dest.size(); |
631 | 10.5k | } |
632 | | }; |
633 | | |
634 | | class color_stop_formatter final : public flag_formatter { |
635 | | public: |
636 | | explicit color_stop_formatter(padding_info padinfo) |
637 | 119k | : flag_formatter(padinfo) {} |
638 | | |
639 | 11.1k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
640 | 11.1k | msg.color_range_end = dest.size(); |
641 | 11.1k | } |
642 | | }; |
643 | | |
644 | | // print source location |
645 | | template <typename ScopedPadder> |
646 | | class source_location_formatter final : public flag_formatter { |
647 | | public: |
648 | | explicit source_location_formatter(padding_info padinfo) |
649 | 40.8k | : flag_formatter(padinfo) {}spdlog::details::source_location_formatter<spdlog::details::scoped_padder>::source_location_formatter(spdlog::details::padding_info) Line | Count | Source | 649 | 20.5k | : flag_formatter(padinfo) {} |
spdlog::details::source_location_formatter<spdlog::details::null_scoped_padder>::source_location_formatter(spdlog::details::padding_info) Line | Count | Source | 649 | 20.2k | : flag_formatter(padinfo) {} |
|
650 | | |
651 | 7.20k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
652 | 7.20k | if (msg.source.empty()) { |
653 | 7.20k | ScopedPadder p(0, padinfo_, dest); |
654 | 7.20k | return; |
655 | 7.20k | } |
656 | | |
657 | 0 | size_t text_size; |
658 | 0 | if (padinfo_.enabled()) { |
659 | | // calc text size for padding based on "filename:line" |
660 | 0 | text_size = std::char_traits<char>::length(msg.source.filename) + |
661 | 0 | ScopedPadder::count_digits(msg.source.line) + 1; |
662 | 0 | } else { |
663 | 0 | text_size = 0; |
664 | 0 | } |
665 | |
|
666 | 0 | ScopedPadder p(text_size, padinfo_, dest); |
667 | 0 | fmt_helper::append_string_view(msg.source.filename, dest); |
668 | 0 | dest.push_back(':'); |
669 | 0 | fmt_helper::append_int(msg.source.line, dest); |
670 | 0 | } spdlog::details::source_location_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 651 | 5.13k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 652 | 5.13k | if (msg.source.empty()) { | 653 | 5.13k | ScopedPadder p(0, padinfo_, dest); | 654 | 5.13k | return; | 655 | 5.13k | } | 656 | | | 657 | 0 | size_t text_size; | 658 | 0 | if (padinfo_.enabled()) { | 659 | | // calc text size for padding based on "filename:line" | 660 | 0 | text_size = std::char_traits<char>::length(msg.source.filename) + | 661 | 0 | ScopedPadder::count_digits(msg.source.line) + 1; | 662 | 0 | } else { | 663 | 0 | text_size = 0; | 664 | 0 | } | 665 | |
| 666 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 667 | 0 | fmt_helper::append_string_view(msg.source.filename, dest); | 668 | 0 | dest.push_back(':'); | 669 | 0 | fmt_helper::append_int(msg.source.line, dest); | 670 | 0 | } |
spdlog::details::source_location_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 651 | 2.06k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 652 | 2.06k | if (msg.source.empty()) { | 653 | 2.06k | ScopedPadder p(0, padinfo_, dest); | 654 | 2.06k | return; | 655 | 2.06k | } | 656 | | | 657 | 0 | size_t text_size; | 658 | 0 | if (padinfo_.enabled()) { | 659 | | // calc text size for padding based on "filename:line" | 660 | 0 | text_size = std::char_traits<char>::length(msg.source.filename) + | 661 | 0 | ScopedPadder::count_digits(msg.source.line) + 1; | 662 | 0 | } else { | 663 | 0 | text_size = 0; | 664 | 0 | } | 665 | |
| 666 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 667 | 0 | fmt_helper::append_string_view(msg.source.filename, dest); | 668 | 0 | dest.push_back(':'); | 669 | 0 | fmt_helper::append_int(msg.source.line, dest); | 670 | 0 | } |
|
671 | | }; |
672 | | |
673 | | // print source filename |
674 | | template <typename ScopedPadder> |
675 | | class source_filename_formatter final : public flag_formatter { |
676 | | public: |
677 | | explicit source_filename_formatter(padding_info padinfo) |
678 | 64.6k | : flag_formatter(padinfo) {}spdlog::details::source_filename_formatter<spdlog::details::scoped_padder>::source_filename_formatter(spdlog::details::padding_info) Line | Count | Source | 678 | 43.3k | : flag_formatter(padinfo) {} |
spdlog::details::source_filename_formatter<spdlog::details::null_scoped_padder>::source_filename_formatter(spdlog::details::padding_info) Line | Count | Source | 678 | 21.3k | : flag_formatter(padinfo) {} |
|
679 | | |
680 | 14.8k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
681 | 14.8k | if (msg.source.empty()) { |
682 | 14.8k | ScopedPadder p(0, padinfo_, dest); |
683 | 14.8k | return; |
684 | 14.8k | } |
685 | 0 | size_t text_size = |
686 | 0 | padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) : 0; |
687 | 0 | ScopedPadder p(text_size, padinfo_, dest); |
688 | 0 | fmt_helper::append_string_view(msg.source.filename, dest); |
689 | 0 | } spdlog::details::source_filename_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 680 | 10.5k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 681 | 10.5k | if (msg.source.empty()) { | 682 | 10.5k | ScopedPadder p(0, padinfo_, dest); | 683 | 10.5k | return; | 684 | 10.5k | } | 685 | 0 | size_t text_size = | 686 | 0 | padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) : 0; | 687 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 688 | 0 | fmt_helper::append_string_view(msg.source.filename, dest); | 689 | 0 | } |
spdlog::details::source_filename_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 680 | 4.28k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 681 | 4.28k | if (msg.source.empty()) { | 682 | 4.28k | ScopedPadder p(0, padinfo_, dest); | 683 | 4.28k | return; | 684 | 4.28k | } | 685 | 0 | size_t text_size = | 686 | 0 | padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) : 0; | 687 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 688 | 0 | fmt_helper::append_string_view(msg.source.filename, dest); | 689 | 0 | } |
|
690 | | }; |
691 | | |
692 | | template <typename ScopedPadder> |
693 | | class short_filename_formatter final : public flag_formatter { |
694 | | public: |
695 | | explicit short_filename_formatter(padding_info padinfo) |
696 | 20.5k | : flag_formatter(padinfo) {}spdlog::details::short_filename_formatter<spdlog::details::scoped_padder>::short_filename_formatter(spdlog::details::padding_info) Line | Count | Source | 696 | 12.7k | : flag_formatter(padinfo) {} |
spdlog::details::short_filename_formatter<spdlog::details::null_scoped_padder>::short_filename_formatter(spdlog::details::padding_info) Line | Count | Source | 696 | 7.85k | : flag_formatter(padinfo) {} |
|
697 | | |
698 | | #ifdef _MSC_VER |
699 | | #pragma warning(push) |
700 | | #pragma warning(disable : 4127) // consider using 'if constexpr' instead |
701 | | #endif // _MSC_VER |
702 | 3.90k | static const char *basename(const char *filename) { |
703 | | // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr |
704 | | // the branch will be elided by optimizations |
705 | 3.90k | if (sizeof(os::folder_seps) == 2) { |
706 | 3.90k | const char *rv = std::strrchr(filename, os::folder_seps[0]); |
707 | 3.90k | return rv != nullptr ? rv + 1 : filename; |
708 | 3.90k | } else { |
709 | 0 | const std::reverse_iterator<const char *> begin(filename + std::strlen(filename)); |
710 | 0 | const std::reverse_iterator<const char *> end(filename); |
711 | |
|
712 | 0 | const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), |
713 | 0 | std::end(os::folder_seps) - 1); |
714 | 0 | return it != end ? it.base() : filename; |
715 | 0 | } |
716 | 3.90k | } spdlog::details::short_filename_formatter<spdlog::details::null_scoped_padder>::basename(char const*) Line | Count | Source | 702 | 3.90k | static const char *basename(const char *filename) { | 703 | | // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr | 704 | | // the branch will be elided by optimizations | 705 | 3.90k | if (sizeof(os::folder_seps) == 2) { | 706 | 3.90k | const char *rv = std::strrchr(filename, os::folder_seps[0]); | 707 | 3.90k | return rv != nullptr ? rv + 1 : filename; | 708 | 3.90k | } else { | 709 | 0 | const std::reverse_iterator<const char *> begin(filename + std::strlen(filename)); | 710 | 0 | const std::reverse_iterator<const char *> end(filename); | 711 | |
| 712 | 0 | const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), | 713 | 0 | std::end(os::folder_seps) - 1); | 714 | 0 | return it != end ? it.base() : filename; | 715 | 0 | } | 716 | 3.90k | } |
Unexecuted instantiation: spdlog::details::short_filename_formatter<spdlog::details::scoped_padder>::basename(char const*) |
717 | | #ifdef _MSC_VER |
718 | | #pragma warning(pop) |
719 | | #endif // _MSC_VER |
720 | | |
721 | 2.70k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
722 | 2.70k | if (msg.source.empty()) { |
723 | 2.70k | ScopedPadder p(0, padinfo_, dest); |
724 | 2.70k | return; |
725 | 2.70k | } |
726 | 0 | auto filename = basename(msg.source.filename); |
727 | 0 | size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(filename) : 0; |
728 | 0 | ScopedPadder p(text_size, padinfo_, dest); |
729 | 0 | fmt_helper::append_string_view(filename, dest); |
730 | 0 | } spdlog::details::short_filename_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 721 | 1.19k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 722 | 1.19k | if (msg.source.empty()) { | 723 | 1.19k | ScopedPadder p(0, padinfo_, dest); | 724 | 1.19k | return; | 725 | 1.19k | } | 726 | 0 | auto filename = basename(msg.source.filename); | 727 | 0 | size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(filename) : 0; | 728 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 729 | 0 | fmt_helper::append_string_view(filename, dest); | 730 | 0 | } |
spdlog::details::short_filename_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 721 | 1.51k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 722 | 1.51k | if (msg.source.empty()) { | 723 | 1.51k | ScopedPadder p(0, padinfo_, dest); | 724 | 1.51k | return; | 725 | 1.51k | } | 726 | 0 | auto filename = basename(msg.source.filename); | 727 | 0 | size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(filename) : 0; | 728 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 729 | 0 | fmt_helper::append_string_view(filename, dest); | 730 | 0 | } |
|
731 | | }; |
732 | | |
733 | | template <typename ScopedPadder> |
734 | | class source_linenum_formatter final : public flag_formatter { |
735 | | public: |
736 | | explicit source_linenum_formatter(padding_info padinfo) |
737 | 83.0k | : flag_formatter(padinfo) {}spdlog::details::source_linenum_formatter<spdlog::details::scoped_padder>::source_linenum_formatter(spdlog::details::padding_info) Line | Count | Source | 737 | 69.1k | : flag_formatter(padinfo) {} |
spdlog::details::source_linenum_formatter<spdlog::details::null_scoped_padder>::source_linenum_formatter(spdlog::details::padding_info) Line | Count | Source | 737 | 13.9k | : flag_formatter(padinfo) {} |
|
738 | | |
739 | 9.51k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
740 | 9.51k | if (msg.source.empty()) { |
741 | 9.51k | ScopedPadder p(0, padinfo_, dest); |
742 | 9.51k | return; |
743 | 9.51k | } |
744 | | |
745 | 0 | auto field_size = ScopedPadder::count_digits(msg.source.line); |
746 | 0 | ScopedPadder p(field_size, padinfo_, dest); |
747 | 0 | fmt_helper::append_int(msg.source.line, dest); |
748 | 0 | } spdlog::details::source_linenum_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 739 | 6.35k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 740 | 6.35k | if (msg.source.empty()) { | 741 | 6.35k | ScopedPadder p(0, padinfo_, dest); | 742 | 6.35k | return; | 743 | 6.35k | } | 744 | | | 745 | 0 | auto field_size = ScopedPadder::count_digits(msg.source.line); | 746 | 0 | ScopedPadder p(field_size, padinfo_, dest); | 747 | 0 | fmt_helper::append_int(msg.source.line, dest); | 748 | 0 | } |
spdlog::details::source_linenum_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 739 | 3.15k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 740 | 3.15k | if (msg.source.empty()) { | 741 | 3.15k | ScopedPadder p(0, padinfo_, dest); | 742 | 3.15k | return; | 743 | 3.15k | } | 744 | | | 745 | 0 | auto field_size = ScopedPadder::count_digits(msg.source.line); | 746 | 0 | ScopedPadder p(field_size, padinfo_, dest); | 747 | 0 | fmt_helper::append_int(msg.source.line, dest); | 748 | 0 | } |
|
749 | | }; |
750 | | |
751 | | // print source funcname |
752 | | template <typename ScopedPadder> |
753 | | class source_funcname_formatter final : public flag_formatter { |
754 | | public: |
755 | | explicit source_funcname_formatter(padding_info padinfo) |
756 | 598k | : flag_formatter(padinfo) {}spdlog::details::source_funcname_formatter<spdlog::details::scoped_padder>::source_funcname_formatter(spdlog::details::padding_info) Line | Count | Source | 756 | 514k | : flag_formatter(padinfo) {} |
spdlog::details::source_funcname_formatter<spdlog::details::null_scoped_padder>::source_funcname_formatter(spdlog::details::padding_info) Line | Count | Source | 756 | 84.4k | : flag_formatter(padinfo) {} |
|
757 | | |
758 | 177k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
759 | 177k | if (msg.source.empty()) { |
760 | 177k | ScopedPadder p(0, padinfo_, dest); |
761 | 177k | return; |
762 | 177k | } |
763 | 0 | size_t text_size = |
764 | 0 | padinfo_.enabled() ? std::char_traits<char>::length(msg.source.funcname) : 0; |
765 | 0 | ScopedPadder p(text_size, padinfo_, dest); |
766 | 0 | fmt_helper::append_string_view(msg.source.funcname, dest); |
767 | 0 | } spdlog::details::source_funcname_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 758 | 167k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 759 | 167k | if (msg.source.empty()) { | 760 | 167k | ScopedPadder p(0, padinfo_, dest); | 761 | 167k | return; | 762 | 167k | } | 763 | 0 | size_t text_size = | 764 | 0 | padinfo_.enabled() ? std::char_traits<char>::length(msg.source.funcname) : 0; | 765 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 766 | 0 | fmt_helper::append_string_view(msg.source.funcname, dest); | 767 | 0 | } |
spdlog::details::source_funcname_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 758 | 10.8k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 759 | 10.8k | if (msg.source.empty()) { | 760 | 10.8k | ScopedPadder p(0, padinfo_, dest); | 761 | 10.8k | return; | 762 | 10.8k | } | 763 | 0 | size_t text_size = | 764 | 0 | padinfo_.enabled() ? std::char_traits<char>::length(msg.source.funcname) : 0; | 765 | 0 | ScopedPadder p(text_size, padinfo_, dest); | 766 | 0 | fmt_helper::append_string_view(msg.source.funcname, dest); | 767 | 0 | } |
|
768 | | }; |
769 | | |
770 | | // print elapsed time since last message |
771 | | template <typename ScopedPadder, typename Units> |
772 | | class elapsed_formatter final : public flag_formatter { |
773 | | public: |
774 | | using DurationUnits = Units; |
775 | | |
776 | | explicit elapsed_formatter(padding_info padinfo) |
777 | 1.63M | : flag_formatter(padinfo), |
778 | 1.63M | last_message_time_(log_clock::now()) {}spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 88.1k | : flag_formatter(padinfo), | 778 | 88.1k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 551k | : flag_formatter(padinfo), | 778 | 551k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 23.4k | : flag_formatter(padinfo), | 778 | 23.4k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 95.3k | : flag_formatter(padinfo), | 778 | 95.3k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 581k | : flag_formatter(padinfo), | 778 | 581k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 25.0k | : flag_formatter(padinfo), | 778 | 25.0k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 81.2k | : flag_formatter(padinfo), | 778 | 81.2k | last_message_time_(log_clock::now()) {} |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::elapsed_formatter(spdlog::details::padding_info) Line | Count | Source | 777 | 187k | : flag_formatter(padinfo), | 778 | 187k | last_message_time_(log_clock::now()) {} |
|
779 | | |
780 | 479k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { |
781 | 479k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); |
782 | 479k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); |
783 | 479k | last_message_time_ = msg.time; |
784 | 479k | auto delta_count = static_cast<size_t>(delta_units.count()); |
785 | 479k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); |
786 | 479k | ScopedPadder p(n_digits, padinfo_, dest); |
787 | 479k | fmt_helper::append_int(delta_count, dest); |
788 | 479k | } spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 22.4k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 22.4k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 22.4k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 22.4k | last_message_time_ = msg.time; | 784 | 22.4k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 22.4k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 22.4k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 22.4k | fmt_helper::append_int(delta_count, dest); | 788 | 22.4k | } |
spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 182k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 182k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 182k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 182k | last_message_time_ = msg.time; | 784 | 182k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 182k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 182k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 182k | fmt_helper::append_int(delta_count, dest); | 788 | 182k | } |
spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 1.49k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 1.49k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 1.49k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 1.49k | last_message_time_ = msg.time; | 784 | 1.49k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 1.49k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 1.49k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 1.49k | fmt_helper::append_int(delta_count, dest); | 788 | 1.49k | } |
spdlog::details::elapsed_formatter<spdlog::details::scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 15.2k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 15.2k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 15.2k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 15.2k | last_message_time_ = msg.time; | 784 | 15.2k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 15.2k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 15.2k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 15.2k | fmt_helper::append_int(delta_count, dest); | 788 | 15.2k | } |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 186k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 186k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 186k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 186k | last_message_time_ = msg.time; | 784 | 186k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 186k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 186k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 186k | fmt_helper::append_int(delta_count, dest); | 788 | 186k | } |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 5.28k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 5.28k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 5.28k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 5.28k | last_message_time_ = msg.time; | 784 | 5.28k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 5.28k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 5.28k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 5.28k | fmt_helper::append_int(delta_count, dest); | 788 | 5.28k | } |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 6.42k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 6.42k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 6.42k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 6.42k | last_message_time_ = msg.time; | 784 | 6.42k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 6.42k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 6.42k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 6.42k | fmt_helper::append_int(delta_count, dest); | 788 | 6.42k | } |
spdlog::details::elapsed_formatter<spdlog::details::null_scoped_padder, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > >::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 780 | 59.7k | void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { | 781 | 59.7k | auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); | 782 | 59.7k | auto delta_units = std::chrono::duration_cast<DurationUnits>(delta); | 783 | 59.7k | last_message_time_ = msg.time; | 784 | 59.7k | auto delta_count = static_cast<size_t>(delta_units.count()); | 785 | 59.7k | auto n_digits = static_cast<size_t>(ScopedPadder::count_digits(delta_count)); | 786 | 59.7k | ScopedPadder p(n_digits, padinfo_, dest); | 787 | 59.7k | fmt_helper::append_int(delta_count, dest); | 788 | 59.7k | } |
|
789 | | |
790 | | private: |
791 | | log_clock::time_point last_message_time_; |
792 | | }; |
793 | | |
794 | | // Class for formatting Mapped Diagnostic Context (MDC) in log messages. |
795 | | // Example: [logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message |
796 | | #ifndef SPDLOG_NO_TLS |
797 | | template <typename ScopedPadder> |
798 | | class mdc_formatter : public flag_formatter { |
799 | | public: |
800 | | explicit mdc_formatter(padding_info padinfo) |
801 | 2.01M | : flag_formatter(padinfo) {}spdlog::details::mdc_formatter<spdlog::details::null_scoped_padder>::mdc_formatter(spdlog::details::padding_info) Line | Count | Source | 801 | 2.00M | : flag_formatter(padinfo) {} |
spdlog::details::mdc_formatter<spdlog::details::scoped_padder>::mdc_formatter(spdlog::details::padding_info) Line | Count | Source | 801 | 12.6k | : flag_formatter(padinfo) {} |
|
802 | | |
803 | 2.92k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { |
804 | 2.92k | auto &mdc_map = mdc::get_context(); |
805 | 2.92k | if (mdc_map.empty()) { |
806 | 2.92k | ScopedPadder p(0, padinfo_, dest); |
807 | 2.92k | return; |
808 | 2.92k | } else { |
809 | 0 | format_mdc(mdc_map, dest); |
810 | 0 | } |
811 | 2.92k | } spdlog::details::mdc_formatter<spdlog::details::null_scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 803 | 1.36k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { | 804 | 1.36k | auto &mdc_map = mdc::get_context(); | 805 | 1.36k | if (mdc_map.empty()) { | 806 | 1.36k | ScopedPadder p(0, padinfo_, dest); | 807 | 1.36k | return; | 808 | 1.36k | } else { | 809 | 0 | format_mdc(mdc_map, dest); | 810 | 0 | } | 811 | 1.36k | } |
spdlog::details::mdc_formatter<spdlog::details::scoped_padder>::format(spdlog::details::log_msg const&, tm const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Line | Count | Source | 803 | 1.55k | void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { | 804 | 1.55k | auto &mdc_map = mdc::get_context(); | 805 | 1.55k | if (mdc_map.empty()) { | 806 | 1.55k | ScopedPadder p(0, padinfo_, dest); | 807 | 1.55k | return; | 808 | 1.55k | } else { | 809 | 0 | format_mdc(mdc_map, dest); | 810 | 0 | } | 811 | 1.55k | } |
|
812 | | |
813 | 0 | void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest) { |
814 | 0 | auto last_element = --mdc_map.end(); |
815 | 0 | for (auto it = mdc_map.begin(); it != mdc_map.end(); ++it) { |
816 | 0 | auto &pair = *it; |
817 | 0 | const auto &key = pair.first; |
818 | 0 | const auto &value = pair.second; |
819 | 0 | size_t content_size = key.size() + value.size() + 1; // 1 for ':' |
820 | |
|
821 | 0 | if (it != last_element) { |
822 | 0 | content_size++; // 1 for ' ' |
823 | 0 | } |
824 | |
|
825 | 0 | ScopedPadder p(content_size, padinfo_, dest); |
826 | 0 | fmt_helper::append_string_view(key, dest); |
827 | 0 | fmt_helper::append_string_view(":", dest); |
828 | 0 | fmt_helper::append_string_view(value, dest); |
829 | 0 | if (it != last_element) { |
830 | 0 | fmt_helper::append_string_view(" ", dest); |
831 | 0 | } |
832 | 0 | } |
833 | 0 | } Unexecuted instantiation: spdlog::details::mdc_formatter<spdlog::details::null_scoped_padder>::format_mdc(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) Unexecuted instantiation: spdlog::details::mdc_formatter<spdlog::details::scoped_padder>::format_mdc(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, fmt::v12::basic_memory_buffer<char, 250ul, fmt::v12::detail::allocator<char> >&) |
834 | | }; |
835 | | #endif |
836 | | |
837 | | // Full info formatter |
838 | | // pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v |
839 | | class full_formatter final : public flag_formatter { |
840 | | public: |
841 | | explicit full_formatter(padding_info padinfo) |
842 | 455k | : flag_formatter(padinfo) {} |
843 | | |
844 | 18.6M | void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { |
845 | 18.6M | using std::chrono::duration_cast; |
846 | 18.6M | using std::chrono::milliseconds; |
847 | 18.6M | using std::chrono::seconds; |
848 | | |
849 | | // cache the date/time part for the next second. |
850 | 18.6M | auto duration = msg.time.time_since_epoch(); |
851 | 18.6M | auto secs = duration_cast<seconds>(duration); |
852 | | |
853 | 18.6M | if (cache_timestamp_ != secs || cached_datetime_.size() == 0) { |
854 | 143k | cached_datetime_.clear(); |
855 | 143k | cached_datetime_.push_back('['); |
856 | 143k | fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_); |
857 | 143k | cached_datetime_.push_back('-'); |
858 | | |
859 | 143k | fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_); |
860 | 143k | cached_datetime_.push_back('-'); |
861 | | |
862 | 143k | fmt_helper::pad2(tm_time.tm_mday, cached_datetime_); |
863 | 143k | cached_datetime_.push_back(' '); |
864 | | |
865 | 143k | fmt_helper::pad2(tm_time.tm_hour, cached_datetime_); |
866 | 143k | cached_datetime_.push_back(':'); |
867 | | |
868 | 143k | fmt_helper::pad2(tm_time.tm_min, cached_datetime_); |
869 | 143k | cached_datetime_.push_back(':'); |
870 | | |
871 | 143k | fmt_helper::pad2(tm_time.tm_sec, cached_datetime_); |
872 | 143k | cached_datetime_.push_back('.'); |
873 | | |
874 | 143k | cache_timestamp_ = secs; |
875 | 143k | } |
876 | 18.6M | dest.append(cached_datetime_.begin(), cached_datetime_.end()); |
877 | | |
878 | 18.6M | auto millis = fmt_helper::time_fraction<milliseconds>(msg.time); |
879 | 18.6M | fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest); |
880 | 18.6M | dest.push_back(']'); |
881 | 18.6M | dest.push_back(' '); |
882 | | |
883 | | // append logger name if exists |
884 | 18.6M | if (msg.logger_name.size() > 0) { |
885 | 18.6M | dest.push_back('['); |
886 | 18.6M | fmt_helper::append_string_view(msg.logger_name, dest); |
887 | 18.6M | dest.push_back(']'); |
888 | 18.6M | dest.push_back(' '); |
889 | 18.6M | } |
890 | | |
891 | 18.6M | dest.push_back('['); |
892 | | // wrap the level name with color |
893 | 18.6M | msg.color_range_start = dest.size(); |
894 | | // fmt_helper::append_string_view(level::to_c_str(msg.level), dest); |
895 | 18.6M | fmt_helper::append_string_view(level::to_string_view(msg.level), dest); |
896 | 18.6M | msg.color_range_end = dest.size(); |
897 | 18.6M | dest.push_back(']'); |
898 | 18.6M | dest.push_back(' '); |
899 | | |
900 | | // add source location if present |
901 | 18.6M | if (!msg.source.empty()) { |
902 | 3.90k | dest.push_back('['); |
903 | 3.90k | const char *filename = |
904 | 3.90k | details::short_filename_formatter<details::null_scoped_padder>::basename( |
905 | 3.90k | msg.source.filename); |
906 | 3.90k | fmt_helper::append_string_view(filename, dest); |
907 | 3.90k | dest.push_back(':'); |
908 | 3.90k | fmt_helper::append_int(msg.source.line, dest); |
909 | 3.90k | dest.push_back(']'); |
910 | 3.90k | dest.push_back(' '); |
911 | 3.90k | } |
912 | | |
913 | 18.6M | #ifndef SPDLOG_NO_TLS |
914 | | // add mdc if present |
915 | 18.6M | auto &mdc_map = mdc::get_context(); |
916 | 18.6M | if (!mdc_map.empty()) { |
917 | 0 | dest.push_back('['); |
918 | 0 | mdc_formatter_.format_mdc(mdc_map, dest); |
919 | 0 | dest.push_back(']'); |
920 | 0 | dest.push_back(' '); |
921 | 0 | } |
922 | 18.6M | #endif |
923 | | // fmt_helper::append_string_view(msg.msg(), dest); |
924 | 18.6M | fmt_helper::append_string_view(msg.payload, dest); |
925 | 18.6M | } |
926 | | |
927 | | private: |
928 | | std::chrono::seconds cache_timestamp_{0}; |
929 | | memory_buf_t cached_datetime_; |
930 | | |
931 | | #ifndef SPDLOG_NO_TLS |
932 | | mdc_formatter<null_scoped_padder> mdc_formatter_{padding_info {}}; |
933 | | #endif |
934 | | }; |
935 | | |
936 | | } // namespace details |
937 | | |
938 | | SPDLOG_INLINE pattern_formatter::pattern_formatter(std::string pattern, |
939 | | pattern_time_type time_type, |
940 | | std::string eol, |
941 | | custom_flags custom_user_flags) |
942 | 19.2k | : pattern_(std::move(pattern)), |
943 | 19.2k | eol_(std::move(eol)), |
944 | 19.2k | pattern_time_type_(time_type), |
945 | 19.2k | need_localtime_(false), |
946 | 19.2k | last_log_secs_(0), |
947 | 19.2k | custom_handlers_(std::move(custom_user_flags)) { |
948 | 19.2k | std::memset(&cached_tm_, 0, sizeof(cached_tm_)); |
949 | 19.2k | compile_pattern_(pattern_); |
950 | 19.2k | } |
951 | | |
952 | | // use by default full formatter for if pattern is not given |
953 | | SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol) |
954 | 7.34k | : pattern_("%+"), |
955 | 7.34k | eol_(std::move(eol)), |
956 | 7.34k | pattern_time_type_(time_type), |
957 | 7.34k | need_localtime_(true), |
958 | 7.34k | last_log_secs_(0) { |
959 | 7.34k | std::memset(&cached_tm_, 0, sizeof(cached_tm_)); |
960 | 7.34k | formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info{})); |
961 | 7.34k | } |
962 | | |
963 | 17.7k | SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const { |
964 | 17.7k | custom_flags cloned_custom_formatters; |
965 | 17.7k | for (auto &it : custom_handlers_) { |
966 | 14.6k | cloned_custom_formatters[it.first] = it.second->clone(); |
967 | 14.6k | } |
968 | 17.7k | auto cloned = details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, |
969 | 17.7k | std::move(cloned_custom_formatters)); |
970 | 17.7k | cloned->need_localtime(need_localtime_); |
971 | 17.7k | #if defined(__GNUC__) && __GNUC__ < 5 |
972 | 17.7k | return std::move(cloned); |
973 | | #else |
974 | | return cloned; |
975 | | #endif |
976 | 17.7k | } |
977 | | |
978 | 18.5M | SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest) { |
979 | 18.5M | if (need_localtime_) { |
980 | 18.5M | const auto secs = |
981 | 18.5M | std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch()); |
982 | 18.5M | if (secs != last_log_secs_) { |
983 | 3.55k | cached_tm_ = get_time_(msg); |
984 | 3.55k | last_log_secs_ = secs; |
985 | 3.55k | } |
986 | 18.5M | } |
987 | | |
988 | 21.3M | for (auto &f : formatters_) { |
989 | 21.3M | f->format(msg, cached_tm_, dest); |
990 | 21.3M | } |
991 | | // write eol |
992 | 18.5M | details::fmt_helper::append_string_view(eol_, dest); |
993 | 18.5M | } |
994 | | |
995 | 7.33k | SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) { |
996 | 7.33k | pattern_ = std::move(pattern); |
997 | 7.33k | need_localtime_ = false; |
998 | 7.33k | compile_pattern_(pattern_); |
999 | 7.33k | } |
1000 | | |
1001 | 17.7k | SPDLOG_INLINE void pattern_formatter::need_localtime(bool need) { need_localtime_ = need; } |
1002 | | |
1003 | 3.55k | SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) { |
1004 | 3.55k | if (pattern_time_type_ == pattern_time_type::local) { |
1005 | 3.55k | return details::os::localtime(log_clock::to_time_t(msg.time)); |
1006 | 3.55k | } |
1007 | 0 | return details::os::gmtime(log_clock::to_time_t(msg.time)); |
1008 | 3.55k | } |
1009 | | |
1010 | | template <typename Padder> |
1011 | 12.6M | SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { |
1012 | | // process custom flags |
1013 | 12.6M | auto it = custom_handlers_.find(flag); |
1014 | 12.6M | if (it != custom_handlers_.end()) { |
1015 | 882k | auto custom_handler = it->second->clone(); |
1016 | 882k | custom_handler->set_padding_info(padding); |
1017 | 882k | formatters_.push_back(std::move(custom_handler)); |
1018 | 882k | return; |
1019 | 882k | } |
1020 | | |
1021 | | // process built-in flags |
1022 | 11.7M | switch (flag) { |
1023 | 448k | case ('+'): // default formatter |
1024 | 448k | formatters_.push_back(details::make_unique<details::full_formatter>(padding)); |
1025 | 448k | need_localtime_ = true; |
1026 | 448k | break; |
1027 | | |
1028 | 124k | case 'n': // logger name |
1029 | 124k | formatters_.push_back(details::make_unique<details::name_formatter<Padder>>(padding)); |
1030 | 124k | break; |
1031 | | |
1032 | 59.9k | case 'l': // level |
1033 | 59.9k | formatters_.push_back(details::make_unique<details::level_formatter<Padder>>(padding)); |
1034 | 59.9k | break; |
1035 | | |
1036 | 155k | case 'L': // short level |
1037 | 155k | formatters_.push_back( |
1038 | 155k | details::make_unique<details::short_level_formatter<Padder>>(padding)); |
1039 | 155k | break; |
1040 | | |
1041 | 164k | case ('t'): // thread id |
1042 | 164k | formatters_.push_back(details::make_unique<details::t_formatter<Padder>>(padding)); |
1043 | 164k | break; |
1044 | | |
1045 | 47.4k | case ('v'): // the message text |
1046 | 47.4k | formatters_.push_back(details::make_unique<details::v_formatter<Padder>>(padding)); |
1047 | 47.4k | break; |
1048 | | |
1049 | 61.2k | case ('a'): // weekday |
1050 | 61.2k | formatters_.push_back(details::make_unique<details::a_formatter<Padder>>(padding)); |
1051 | 61.2k | need_localtime_ = true; |
1052 | 61.2k | break; |
1053 | | |
1054 | 99.1k | case ('A'): // short weekday |
1055 | 99.1k | formatters_.push_back(details::make_unique<details::A_formatter<Padder>>(padding)); |
1056 | 99.1k | need_localtime_ = true; |
1057 | 99.1k | break; |
1058 | | |
1059 | 164k | case ('b'): |
1060 | 184k | case ('h'): // month |
1061 | 184k | formatters_.push_back(details::make_unique<details::b_formatter<Padder>>(padding)); |
1062 | 184k | need_localtime_ = true; |
1063 | 184k | break; |
1064 | | |
1065 | 117k | case ('B'): // short month |
1066 | 117k | formatters_.push_back(details::make_unique<details::B_formatter<Padder>>(padding)); |
1067 | 117k | need_localtime_ = true; |
1068 | 117k | break; |
1069 | | |
1070 | 129k | case ('c'): // datetime |
1071 | 129k | formatters_.push_back(details::make_unique<details::c_formatter<Padder>>(padding)); |
1072 | 129k | need_localtime_ = true; |
1073 | 129k | break; |
1074 | | |
1075 | 45.1k | case ('C'): // year 2 digits |
1076 | 45.1k | formatters_.push_back(details::make_unique<details::C_formatter<Padder>>(padding)); |
1077 | 45.1k | need_localtime_ = true; |
1078 | 45.1k | break; |
1079 | | |
1080 | 68.1k | case ('Y'): // year 4 digits |
1081 | 68.1k | formatters_.push_back(details::make_unique<details::Y_formatter<Padder>>(padding)); |
1082 | 68.1k | need_localtime_ = true; |
1083 | 68.1k | break; |
1084 | | |
1085 | 49.5k | case ('D'): |
1086 | 159k | case ('x'): // datetime MM/DD/YY |
1087 | 159k | formatters_.push_back(details::make_unique<details::D_formatter<Padder>>(padding)); |
1088 | 159k | need_localtime_ = true; |
1089 | 159k | break; |
1090 | | |
1091 | 124k | case ('m'): // month 1-12 |
1092 | 124k | formatters_.push_back(details::make_unique<details::m_formatter<Padder>>(padding)); |
1093 | 124k | need_localtime_ = true; |
1094 | 124k | break; |
1095 | | |
1096 | 141k | case ('d'): // day of month 1-31 |
1097 | 141k | formatters_.push_back(details::make_unique<details::d_formatter<Padder>>(padding)); |
1098 | 141k | need_localtime_ = true; |
1099 | 141k | break; |
1100 | | |
1101 | 406k | case ('H'): // hours 24 |
1102 | 406k | formatters_.push_back(details::make_unique<details::H_formatter<Padder>>(padding)); |
1103 | 406k | need_localtime_ = true; |
1104 | 406k | break; |
1105 | | |
1106 | 88.8k | case ('I'): // hours 12 |
1107 | 88.8k | formatters_.push_back(details::make_unique<details::I_formatter<Padder>>(padding)); |
1108 | 88.8k | need_localtime_ = true; |
1109 | 88.8k | break; |
1110 | | |
1111 | 569k | case ('M'): // minutes |
1112 | 569k | formatters_.push_back(details::make_unique<details::M_formatter<Padder>>(padding)); |
1113 | 569k | need_localtime_ = true; |
1114 | 569k | break; |
1115 | | |
1116 | 365k | case ('S'): // seconds |
1117 | 365k | formatters_.push_back(details::make_unique<details::S_formatter<Padder>>(padding)); |
1118 | 365k | need_localtime_ = true; |
1119 | 365k | break; |
1120 | | |
1121 | 119k | case ('e'): // milliseconds |
1122 | 119k | formatters_.push_back(details::make_unique<details::e_formatter<Padder>>(padding)); |
1123 | 119k | break; |
1124 | | |
1125 | 270k | case ('f'): // microseconds |
1126 | 270k | formatters_.push_back(details::make_unique<details::f_formatter<Padder>>(padding)); |
1127 | 270k | break; |
1128 | | |
1129 | 344k | case ('F'): // nanoseconds |
1130 | 344k | formatters_.push_back(details::make_unique<details::F_formatter<Padder>>(padding)); |
1131 | 344k | break; |
1132 | | |
1133 | 134k | case ('E'): // seconds since epoch |
1134 | 134k | formatters_.push_back(details::make_unique<details::E_formatter<Padder>>(padding)); |
1135 | 134k | break; |
1136 | | |
1137 | 73.1k | case ('p'): // am/pm |
1138 | 73.1k | formatters_.push_back(details::make_unique<details::p_formatter<Padder>>(padding)); |
1139 | 73.1k | need_localtime_ = true; |
1140 | 73.1k | break; |
1141 | | |
1142 | 140k | case ('r'): // 12 hour clock 02:55:02 pm |
1143 | 140k | formatters_.push_back(details::make_unique<details::r_formatter<Padder>>(padding)); |
1144 | 140k | need_localtime_ = true; |
1145 | 140k | break; |
1146 | | |
1147 | 157k | case ('R'): // 24-hour HH:MM time |
1148 | 157k | formatters_.push_back(details::make_unique<details::R_formatter<Padder>>(padding)); |
1149 | 157k | need_localtime_ = true; |
1150 | 157k | break; |
1151 | | |
1152 | 79.3k | case ('T'): |
1153 | 161k | case ('X'): // ISO 8601 time format (HH:MM:SS) |
1154 | 161k | formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding)); |
1155 | 161k | need_localtime_ = true; |
1156 | 161k | break; |
1157 | | |
1158 | 506k | case ('z'): // timezone |
1159 | 506k | formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding)); |
1160 | 506k | need_localtime_ = true; |
1161 | 506k | break; |
1162 | | |
1163 | 193k | case ('P'): // pid |
1164 | 193k | formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding)); |
1165 | 193k | break; |
1166 | | |
1167 | 70.3k | case ('^'): // color range start |
1168 | 70.3k | formatters_.push_back(details::make_unique<details::color_start_formatter>(padding)); |
1169 | 70.3k | break; |
1170 | | |
1171 | 119k | case ('$'): // color range end |
1172 | 119k | formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding)); |
1173 | 119k | break; |
1174 | | |
1175 | 40.8k | case ('@'): // source location (filename:filenumber) |
1176 | 40.8k | formatters_.push_back( |
1177 | 40.8k | details::make_unique<details::source_location_formatter<Padder>>(padding)); |
1178 | 40.8k | break; |
1179 | | |
1180 | 20.5k | case ('s'): // short source filename - without directory name |
1181 | 20.5k | formatters_.push_back( |
1182 | 20.5k | details::make_unique<details::short_filename_formatter<Padder>>(padding)); |
1183 | 20.5k | break; |
1184 | | |
1185 | 64.6k | case ('g'): // full source filename |
1186 | 64.6k | formatters_.push_back( |
1187 | 64.6k | details::make_unique<details::source_filename_formatter<Padder>>(padding)); |
1188 | 64.6k | break; |
1189 | | |
1190 | 83.0k | case ('#'): // source line number |
1191 | 83.0k | formatters_.push_back( |
1192 | 83.0k | details::make_unique<details::source_linenum_formatter<Padder>>(padding)); |
1193 | 83.0k | break; |
1194 | | |
1195 | 559k | case ('!'): // source funcname |
1196 | 559k | formatters_.push_back( |
1197 | 559k | details::make_unique<details::source_funcname_formatter<Padder>>(padding)); |
1198 | 559k | break; |
1199 | | |
1200 | 933k | case ('%'): // % char |
1201 | 933k | formatters_.push_back(details::make_unique<details::ch_formatter>('%')); |
1202 | 933k | break; |
1203 | | |
1204 | 669k | case ('u'): // elapsed time since last log message in nanos |
1205 | 669k | formatters_.push_back( |
1206 | 669k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>( |
1207 | 669k | padding)); |
1208 | 669k | break; |
1209 | | |
1210 | 576k | case ('i'): // elapsed time since last log message in micros |
1211 | 576k | formatters_.push_back( |
1212 | 576k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>( |
1213 | 576k | padding)); |
1214 | 576k | break; |
1215 | | |
1216 | 104k | case ('o'): // elapsed time since last log message in millis |
1217 | 104k | formatters_.push_back( |
1218 | 104k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>( |
1219 | 104k | padding)); |
1220 | 104k | break; |
1221 | | |
1222 | 282k | case ('O'): // elapsed time since last log message in seconds |
1223 | 282k | formatters_.push_back( |
1224 | 282k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>( |
1225 | 282k | padding)); |
1226 | 282k | break; |
1227 | | |
1228 | 0 | #ifndef SPDLOG_NO_TLS // mdc formatter requires TLS support |
1229 | 1.55M | case ('&'): |
1230 | 1.55M | formatters_.push_back(details::make_unique<details::mdc_formatter<Padder>>(padding)); |
1231 | 1.55M | break; |
1232 | 0 | #endif |
1233 | | |
1234 | 1.04M | default: // Unknown flag appears as is |
1235 | 1.04M | auto unknown_flag = details::make_unique<details::aggregate_formatter>(); |
1236 | | |
1237 | 1.04M | if (!padding.truncate_) { |
1238 | 1.00M | unknown_flag->add_ch('%'); |
1239 | 1.00M | unknown_flag->add_ch(flag); |
1240 | 1.00M | formatters_.push_back((std::move(unknown_flag))); |
1241 | 1.00M | } |
1242 | | // fix issue #1617 (prev char was '!' and should have been treated as funcname flag |
1243 | | // instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some |
1244 | | // message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message" |
1245 | 39.0k | else { |
1246 | 39.0k | padding.truncate_ = false; |
1247 | 39.0k | formatters_.push_back( |
1248 | 39.0k | details::make_unique<details::source_funcname_formatter<Padder>>(padding)); |
1249 | 39.0k | unknown_flag->add_ch(flag); |
1250 | 39.0k | formatters_.push_back((std::move(unknown_flag))); |
1251 | 39.0k | } |
1252 | | |
1253 | 1.04M | break; |
1254 | 11.7M | } |
1255 | 11.7M | } void spdlog::pattern_formatter::handle_flag_<spdlog::details::scoped_padder>(char, spdlog::details::padding_info) Line | Count | Source | 1011 | 3.94M | SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { | 1012 | | // process custom flags | 1013 | 3.94M | auto it = custom_handlers_.find(flag); | 1014 | 3.94M | if (it != custom_handlers_.end()) { | 1015 | 11.2k | auto custom_handler = it->second->clone(); | 1016 | 11.2k | custom_handler->set_padding_info(padding); | 1017 | 11.2k | formatters_.push_back(std::move(custom_handler)); | 1018 | 11.2k | return; | 1019 | 11.2k | } | 1020 | | | 1021 | | // process built-in flags | 1022 | 3.92M | switch (flag) { | 1023 | 19.7k | case ('+'): // default formatter | 1024 | 19.7k | formatters_.push_back(details::make_unique<details::full_formatter>(padding)); | 1025 | 19.7k | need_localtime_ = true; | 1026 | 19.7k | break; | 1027 | | | 1028 | 70.7k | case 'n': // logger name | 1029 | 70.7k | formatters_.push_back(details::make_unique<details::name_formatter<Padder>>(padding)); | 1030 | 70.7k | break; | 1031 | | | 1032 | 28.6k | case 'l': // level | 1033 | 28.6k | formatters_.push_back(details::make_unique<details::level_formatter<Padder>>(padding)); | 1034 | 28.6k | break; | 1035 | | | 1036 | 42.9k | case 'L': // short level | 1037 | 42.9k | formatters_.push_back( | 1038 | 42.9k | details::make_unique<details::short_level_formatter<Padder>>(padding)); | 1039 | 42.9k | break; | 1040 | | | 1041 | 59.2k | case ('t'): // thread id | 1042 | 59.2k | formatters_.push_back(details::make_unique<details::t_formatter<Padder>>(padding)); | 1043 | 59.2k | break; | 1044 | | | 1045 | 22.1k | case ('v'): // the message text | 1046 | 22.1k | formatters_.push_back(details::make_unique<details::v_formatter<Padder>>(padding)); | 1047 | 22.1k | break; | 1048 | | | 1049 | 36.5k | case ('a'): // weekday | 1050 | 36.5k | formatters_.push_back(details::make_unique<details::a_formatter<Padder>>(padding)); | 1051 | 36.5k | need_localtime_ = true; | 1052 | 36.5k | break; | 1053 | | | 1054 | 37.0k | case ('A'): // short weekday | 1055 | 37.0k | formatters_.push_back(details::make_unique<details::A_formatter<Padder>>(padding)); | 1056 | 37.0k | need_localtime_ = true; | 1057 | 37.0k | break; | 1058 | | | 1059 | 21.5k | case ('b'): | 1060 | 29.2k | case ('h'): // month | 1061 | 29.2k | formatters_.push_back(details::make_unique<details::b_formatter<Padder>>(padding)); | 1062 | 29.2k | need_localtime_ = true; | 1063 | 29.2k | break; | 1064 | | | 1065 | 53.6k | case ('B'): // short month | 1066 | 53.6k | formatters_.push_back(details::make_unique<details::B_formatter<Padder>>(padding)); | 1067 | 53.6k | need_localtime_ = true; | 1068 | 53.6k | break; | 1069 | | | 1070 | 68.4k | case ('c'): // datetime | 1071 | 68.4k | formatters_.push_back(details::make_unique<details::c_formatter<Padder>>(padding)); | 1072 | 68.4k | need_localtime_ = true; | 1073 | 68.4k | break; | 1074 | | | 1075 | 16.1k | case ('C'): // year 2 digits | 1076 | 16.1k | formatters_.push_back(details::make_unique<details::C_formatter<Padder>>(padding)); | 1077 | 16.1k | need_localtime_ = true; | 1078 | 16.1k | break; | 1079 | | | 1080 | 55.2k | case ('Y'): // year 4 digits | 1081 | 55.2k | formatters_.push_back(details::make_unique<details::Y_formatter<Padder>>(padding)); | 1082 | 55.2k | need_localtime_ = true; | 1083 | 55.2k | break; | 1084 | | | 1085 | 21.6k | case ('D'): | 1086 | 43.9k | case ('x'): // datetime MM/DD/YY | 1087 | 43.9k | formatters_.push_back(details::make_unique<details::D_formatter<Padder>>(padding)); | 1088 | 43.9k | need_localtime_ = true; | 1089 | 43.9k | break; | 1090 | | | 1091 | 104k | case ('m'): // month 1-12 | 1092 | 104k | formatters_.push_back(details::make_unique<details::m_formatter<Padder>>(padding)); | 1093 | 104k | need_localtime_ = true; | 1094 | 104k | break; | 1095 | | | 1096 | 60.6k | case ('d'): // day of month 1-31 | 1097 | 60.6k | formatters_.push_back(details::make_unique<details::d_formatter<Padder>>(padding)); | 1098 | 60.6k | need_localtime_ = true; | 1099 | 60.6k | break; | 1100 | | | 1101 | 43.2k | case ('H'): // hours 24 | 1102 | 43.2k | formatters_.push_back(details::make_unique<details::H_formatter<Padder>>(padding)); | 1103 | 43.2k | need_localtime_ = true; | 1104 | 43.2k | break; | 1105 | | | 1106 | 70.0k | case ('I'): // hours 12 | 1107 | 70.0k | formatters_.push_back(details::make_unique<details::I_formatter<Padder>>(padding)); | 1108 | 70.0k | need_localtime_ = true; | 1109 | 70.0k | break; | 1110 | | | 1111 | 154k | case ('M'): // minutes | 1112 | 154k | formatters_.push_back(details::make_unique<details::M_formatter<Padder>>(padding)); | 1113 | 154k | need_localtime_ = true; | 1114 | 154k | break; | 1115 | | | 1116 | 8.46k | case ('S'): // seconds | 1117 | 8.46k | formatters_.push_back(details::make_unique<details::S_formatter<Padder>>(padding)); | 1118 | 8.46k | need_localtime_ = true; | 1119 | 8.46k | break; | 1120 | | | 1121 | 53.1k | case ('e'): // milliseconds | 1122 | 53.1k | formatters_.push_back(details::make_unique<details::e_formatter<Padder>>(padding)); | 1123 | 53.1k | break; | 1124 | | | 1125 | 68.2k | case ('f'): // microseconds | 1126 | 68.2k | formatters_.push_back(details::make_unique<details::f_formatter<Padder>>(padding)); | 1127 | 68.2k | break; | 1128 | | | 1129 | 308k | case ('F'): // nanoseconds | 1130 | 308k | formatters_.push_back(details::make_unique<details::F_formatter<Padder>>(padding)); | 1131 | 308k | break; | 1132 | | | 1133 | 108k | case ('E'): // seconds since epoch | 1134 | 108k | formatters_.push_back(details::make_unique<details::E_formatter<Padder>>(padding)); | 1135 | 108k | break; | 1136 | | | 1137 | 50.3k | case ('p'): // am/pm | 1138 | 50.3k | formatters_.push_back(details::make_unique<details::p_formatter<Padder>>(padding)); | 1139 | 50.3k | need_localtime_ = true; | 1140 | 50.3k | break; | 1141 | | | 1142 | 64.6k | case ('r'): // 12 hour clock 02:55:02 pm | 1143 | 64.6k | formatters_.push_back(details::make_unique<details::r_formatter<Padder>>(padding)); | 1144 | 64.6k | need_localtime_ = true; | 1145 | 64.6k | break; | 1146 | | | 1147 | 17.7k | case ('R'): // 24-hour HH:MM time | 1148 | 17.7k | formatters_.push_back(details::make_unique<details::R_formatter<Padder>>(padding)); | 1149 | 17.7k | need_localtime_ = true; | 1150 | 17.7k | break; | 1151 | | | 1152 | 23.2k | case ('T'): | 1153 | 62.5k | case ('X'): // ISO 8601 time format (HH:MM:SS) | 1154 | 62.5k | formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding)); | 1155 | 62.5k | need_localtime_ = true; | 1156 | 62.5k | break; | 1157 | | | 1158 | 98.4k | case ('z'): // timezone | 1159 | 98.4k | formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding)); | 1160 | 98.4k | need_localtime_ = true; | 1161 | 98.4k | break; | 1162 | | | 1163 | 94.9k | case ('P'): // pid | 1164 | 94.9k | formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding)); | 1165 | 94.9k | break; | 1166 | | | 1167 | 20.9k | case ('^'): // color range start | 1168 | 20.9k | formatters_.push_back(details::make_unique<details::color_start_formatter>(padding)); | 1169 | 20.9k | break; | 1170 | | | 1171 | 52.0k | case ('$'): // color range end | 1172 | 52.0k | formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding)); | 1173 | 52.0k | break; | 1174 | | | 1175 | 20.5k | case ('@'): // source location (filename:filenumber) | 1176 | 20.5k | formatters_.push_back( | 1177 | 20.5k | details::make_unique<details::source_location_formatter<Padder>>(padding)); | 1178 | 20.5k | break; | 1179 | | | 1180 | 12.7k | case ('s'): // short source filename - without directory name | 1181 | 12.7k | formatters_.push_back( | 1182 | 12.7k | details::make_unique<details::short_filename_formatter<Padder>>(padding)); | 1183 | 12.7k | break; | 1184 | | | 1185 | 43.3k | case ('g'): // full source filename | 1186 | 43.3k | formatters_.push_back( | 1187 | 43.3k | details::make_unique<details::source_filename_formatter<Padder>>(padding)); | 1188 | 43.3k | break; | 1189 | | | 1190 | 69.1k | case ('#'): // source line number | 1191 | 69.1k | formatters_.push_back( | 1192 | 69.1k | details::make_unique<details::source_linenum_formatter<Padder>>(padding)); | 1193 | 69.1k | break; | 1194 | | | 1195 | 475k | case ('!'): // source funcname | 1196 | 475k | formatters_.push_back( | 1197 | 475k | details::make_unique<details::source_funcname_formatter<Padder>>(padding)); | 1198 | 475k | break; | 1199 | | | 1200 | 154k | case ('%'): // % char | 1201 | 154k | formatters_.push_back(details::make_unique<details::ch_formatter>('%')); | 1202 | 154k | break; | 1203 | | | 1204 | 88.1k | case ('u'): // elapsed time since last log message in nanos | 1205 | 88.1k | formatters_.push_back( | 1206 | 88.1k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>( | 1207 | 88.1k | padding)); | 1208 | 88.1k | break; | 1209 | | | 1210 | 551k | case ('i'): // elapsed time since last log message in micros | 1211 | 551k | formatters_.push_back( | 1212 | 551k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>( | 1213 | 551k | padding)); | 1214 | 551k | break; | 1215 | | | 1216 | 23.4k | case ('o'): // elapsed time since last log message in millis | 1217 | 23.4k | formatters_.push_back( | 1218 | 23.4k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>( | 1219 | 23.4k | padding)); | 1220 | 23.4k | break; | 1221 | | | 1222 | 95.3k | case ('O'): // elapsed time since last log message in seconds | 1223 | 95.3k | formatters_.push_back( | 1224 | 95.3k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>( | 1225 | 95.3k | padding)); | 1226 | 95.3k | break; | 1227 | | | 1228 | 0 | #ifndef SPDLOG_NO_TLS // mdc formatter requires TLS support | 1229 | 12.6k | case ('&'): | 1230 | 12.6k | formatters_.push_back(details::make_unique<details::mdc_formatter<Padder>>(padding)); | 1231 | 12.6k | break; | 1232 | 0 | #endif | 1233 | | | 1234 | 355k | default: // Unknown flag appears as is | 1235 | 355k | auto unknown_flag = details::make_unique<details::aggregate_formatter>(); | 1236 | | | 1237 | 355k | if (!padding.truncate_) { | 1238 | 316k | unknown_flag->add_ch('%'); | 1239 | 316k | unknown_flag->add_ch(flag); | 1240 | 316k | formatters_.push_back((std::move(unknown_flag))); | 1241 | 316k | } | 1242 | | // fix issue #1617 (prev char was '!' and should have been treated as funcname flag | 1243 | | // instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some | 1244 | | // message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message" | 1245 | 39.0k | else { | 1246 | 39.0k | padding.truncate_ = false; | 1247 | 39.0k | formatters_.push_back( | 1248 | 39.0k | details::make_unique<details::source_funcname_formatter<Padder>>(padding)); | 1249 | 39.0k | unknown_flag->add_ch(flag); | 1250 | 39.0k | formatters_.push_back((std::move(unknown_flag))); | 1251 | 39.0k | } | 1252 | | | 1253 | 355k | break; | 1254 | 3.92M | } | 1255 | 3.92M | } |
void spdlog::pattern_formatter::handle_flag_<spdlog::details::null_scoped_padder>(char, spdlog::details::padding_info) Line | Count | Source | 1011 | 8.73M | SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { | 1012 | | // process custom flags | 1013 | 8.73M | auto it = custom_handlers_.find(flag); | 1014 | 8.73M | if (it != custom_handlers_.end()) { | 1015 | 871k | auto custom_handler = it->second->clone(); | 1016 | 871k | custom_handler->set_padding_info(padding); | 1017 | 871k | formatters_.push_back(std::move(custom_handler)); | 1018 | 871k | return; | 1019 | 871k | } | 1020 | | | 1021 | | // process built-in flags | 1022 | 7.86M | switch (flag) { | 1023 | 428k | case ('+'): // default formatter | 1024 | 428k | formatters_.push_back(details::make_unique<details::full_formatter>(padding)); | 1025 | 428k | need_localtime_ = true; | 1026 | 428k | break; | 1027 | | | 1028 | 54.0k | case 'n': // logger name | 1029 | 54.0k | formatters_.push_back(details::make_unique<details::name_formatter<Padder>>(padding)); | 1030 | 54.0k | break; | 1031 | | | 1032 | 31.3k | case 'l': // level | 1033 | 31.3k | formatters_.push_back(details::make_unique<details::level_formatter<Padder>>(padding)); | 1034 | 31.3k | break; | 1035 | | | 1036 | 112k | case 'L': // short level | 1037 | 112k | formatters_.push_back( | 1038 | 112k | details::make_unique<details::short_level_formatter<Padder>>(padding)); | 1039 | 112k | break; | 1040 | | | 1041 | 105k | case ('t'): // thread id | 1042 | 105k | formatters_.push_back(details::make_unique<details::t_formatter<Padder>>(padding)); | 1043 | 105k | break; | 1044 | | | 1045 | 25.2k | case ('v'): // the message text | 1046 | 25.2k | formatters_.push_back(details::make_unique<details::v_formatter<Padder>>(padding)); | 1047 | 25.2k | break; | 1048 | | | 1049 | 24.7k | case ('a'): // weekday | 1050 | 24.7k | formatters_.push_back(details::make_unique<details::a_formatter<Padder>>(padding)); | 1051 | 24.7k | need_localtime_ = true; | 1052 | 24.7k | break; | 1053 | | | 1054 | 62.1k | case ('A'): // short weekday | 1055 | 62.1k | formatters_.push_back(details::make_unique<details::A_formatter<Padder>>(padding)); | 1056 | 62.1k | need_localtime_ = true; | 1057 | 62.1k | break; | 1058 | | | 1059 | 143k | case ('b'): | 1060 | 154k | case ('h'): // month | 1061 | 154k | formatters_.push_back(details::make_unique<details::b_formatter<Padder>>(padding)); | 1062 | 154k | need_localtime_ = true; | 1063 | 154k | break; | 1064 | | | 1065 | 63.9k | case ('B'): // short month | 1066 | 63.9k | formatters_.push_back(details::make_unique<details::B_formatter<Padder>>(padding)); | 1067 | 63.9k | need_localtime_ = true; | 1068 | 63.9k | break; | 1069 | | | 1070 | 60.8k | case ('c'): // datetime | 1071 | 60.8k | formatters_.push_back(details::make_unique<details::c_formatter<Padder>>(padding)); | 1072 | 60.8k | need_localtime_ = true; | 1073 | 60.8k | break; | 1074 | | | 1075 | 29.0k | case ('C'): // year 2 digits | 1076 | 29.0k | formatters_.push_back(details::make_unique<details::C_formatter<Padder>>(padding)); | 1077 | 29.0k | need_localtime_ = true; | 1078 | 29.0k | break; | 1079 | | | 1080 | 12.9k | case ('Y'): // year 4 digits | 1081 | 12.9k | formatters_.push_back(details::make_unique<details::Y_formatter<Padder>>(padding)); | 1082 | 12.9k | need_localtime_ = true; | 1083 | 12.9k | break; | 1084 | | | 1085 | 27.8k | case ('D'): | 1086 | 115k | case ('x'): // datetime MM/DD/YY | 1087 | 115k | formatters_.push_back(details::make_unique<details::D_formatter<Padder>>(padding)); | 1088 | 115k | need_localtime_ = true; | 1089 | 115k | break; | 1090 | | | 1091 | 19.8k | case ('m'): // month 1-12 | 1092 | 19.8k | formatters_.push_back(details::make_unique<details::m_formatter<Padder>>(padding)); | 1093 | 19.8k | need_localtime_ = true; | 1094 | 19.8k | break; | 1095 | | | 1096 | 80.7k | case ('d'): // day of month 1-31 | 1097 | 80.7k | formatters_.push_back(details::make_unique<details::d_formatter<Padder>>(padding)); | 1098 | 80.7k | need_localtime_ = true; | 1099 | 80.7k | break; | 1100 | | | 1101 | 363k | case ('H'): // hours 24 | 1102 | 363k | formatters_.push_back(details::make_unique<details::H_formatter<Padder>>(padding)); | 1103 | 363k | need_localtime_ = true; | 1104 | 363k | break; | 1105 | | | 1106 | 18.8k | case ('I'): // hours 12 | 1107 | 18.8k | formatters_.push_back(details::make_unique<details::I_formatter<Padder>>(padding)); | 1108 | 18.8k | need_localtime_ = true; | 1109 | 18.8k | break; | 1110 | | | 1111 | 414k | case ('M'): // minutes | 1112 | 414k | formatters_.push_back(details::make_unique<details::M_formatter<Padder>>(padding)); | 1113 | 414k | need_localtime_ = true; | 1114 | 414k | break; | 1115 | | | 1116 | 357k | case ('S'): // seconds | 1117 | 357k | formatters_.push_back(details::make_unique<details::S_formatter<Padder>>(padding)); | 1118 | 357k | need_localtime_ = true; | 1119 | 357k | break; | 1120 | | | 1121 | 66.0k | case ('e'): // milliseconds | 1122 | 66.0k | formatters_.push_back(details::make_unique<details::e_formatter<Padder>>(padding)); | 1123 | 66.0k | break; | 1124 | | | 1125 | 201k | case ('f'): // microseconds | 1126 | 201k | formatters_.push_back(details::make_unique<details::f_formatter<Padder>>(padding)); | 1127 | 201k | break; | 1128 | | | 1129 | 36.0k | case ('F'): // nanoseconds | 1130 | 36.0k | formatters_.push_back(details::make_unique<details::F_formatter<Padder>>(padding)); | 1131 | 36.0k | break; | 1132 | | | 1133 | 26.2k | case ('E'): // seconds since epoch | 1134 | 26.2k | formatters_.push_back(details::make_unique<details::E_formatter<Padder>>(padding)); | 1135 | 26.2k | break; | 1136 | | | 1137 | 22.8k | case ('p'): // am/pm | 1138 | 22.8k | formatters_.push_back(details::make_unique<details::p_formatter<Padder>>(padding)); | 1139 | 22.8k | need_localtime_ = true; | 1140 | 22.8k | break; | 1141 | | | 1142 | 75.6k | case ('r'): // 12 hour clock 02:55:02 pm | 1143 | 75.6k | formatters_.push_back(details::make_unique<details::r_formatter<Padder>>(padding)); | 1144 | 75.6k | need_localtime_ = true; | 1145 | 75.6k | break; | 1146 | | | 1147 | 140k | case ('R'): // 24-hour HH:MM time | 1148 | 140k | formatters_.push_back(details::make_unique<details::R_formatter<Padder>>(padding)); | 1149 | 140k | need_localtime_ = true; | 1150 | 140k | break; | 1151 | | | 1152 | 56.0k | case ('T'): | 1153 | 98.8k | case ('X'): // ISO 8601 time format (HH:MM:SS) | 1154 | 98.8k | formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding)); | 1155 | 98.8k | need_localtime_ = true; | 1156 | 98.8k | break; | 1157 | | | 1158 | 408k | case ('z'): // timezone | 1159 | 408k | formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding)); | 1160 | 408k | need_localtime_ = true; | 1161 | 408k | break; | 1162 | | | 1163 | 98.2k | case ('P'): // pid | 1164 | 98.2k | formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding)); | 1165 | 98.2k | break; | 1166 | | | 1167 | 49.3k | case ('^'): // color range start | 1168 | 49.3k | formatters_.push_back(details::make_unique<details::color_start_formatter>(padding)); | 1169 | 49.3k | break; | 1170 | | | 1171 | 67.3k | case ('$'): // color range end | 1172 | 67.3k | formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding)); | 1173 | 67.3k | break; | 1174 | | | 1175 | 20.2k | case ('@'): // source location (filename:filenumber) | 1176 | 20.2k | formatters_.push_back( | 1177 | 20.2k | details::make_unique<details::source_location_formatter<Padder>>(padding)); | 1178 | 20.2k | break; | 1179 | | | 1180 | 7.85k | case ('s'): // short source filename - without directory name | 1181 | 7.85k | formatters_.push_back( | 1182 | 7.85k | details::make_unique<details::short_filename_formatter<Padder>>(padding)); | 1183 | 7.85k | break; | 1184 | | | 1185 | 21.3k | case ('g'): // full source filename | 1186 | 21.3k | formatters_.push_back( | 1187 | 21.3k | details::make_unique<details::source_filename_formatter<Padder>>(padding)); | 1188 | 21.3k | break; | 1189 | | | 1190 | 13.9k | case ('#'): // source line number | 1191 | 13.9k | formatters_.push_back( | 1192 | 13.9k | details::make_unique<details::source_linenum_formatter<Padder>>(padding)); | 1193 | 13.9k | break; | 1194 | | | 1195 | 84.4k | case ('!'): // source funcname | 1196 | 84.4k | formatters_.push_back( | 1197 | 84.4k | details::make_unique<details::source_funcname_formatter<Padder>>(padding)); | 1198 | 84.4k | break; | 1199 | | | 1200 | 778k | case ('%'): // % char | 1201 | 778k | formatters_.push_back(details::make_unique<details::ch_formatter>('%')); | 1202 | 778k | break; | 1203 | | | 1204 | 581k | case ('u'): // elapsed time since last log message in nanos | 1205 | 581k | formatters_.push_back( | 1206 | 581k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>( | 1207 | 581k | padding)); | 1208 | 581k | break; | 1209 | | | 1210 | 25.0k | case ('i'): // elapsed time since last log message in micros | 1211 | 25.0k | formatters_.push_back( | 1212 | 25.0k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>( | 1213 | 25.0k | padding)); | 1214 | 25.0k | break; | 1215 | | | 1216 | 81.2k | case ('o'): // elapsed time since last log message in millis | 1217 | 81.2k | formatters_.push_back( | 1218 | 81.2k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>( | 1219 | 81.2k | padding)); | 1220 | 81.2k | break; | 1221 | | | 1222 | 187k | case ('O'): // elapsed time since last log message in seconds | 1223 | 187k | formatters_.push_back( | 1224 | 187k | details::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>( | 1225 | 187k | padding)); | 1226 | 187k | break; | 1227 | | | 1228 | 0 | #ifndef SPDLOG_NO_TLS // mdc formatter requires TLS support | 1229 | 1.54M | case ('&'): | 1230 | 1.54M | formatters_.push_back(details::make_unique<details::mdc_formatter<Padder>>(padding)); | 1231 | 1.54M | break; | 1232 | 0 | #endif | 1233 | | | 1234 | 690k | default: // Unknown flag appears as is | 1235 | 690k | auto unknown_flag = details::make_unique<details::aggregate_formatter>(); | 1236 | | | 1237 | 690k | if (!padding.truncate_) { | 1238 | 690k | unknown_flag->add_ch('%'); | 1239 | 690k | unknown_flag->add_ch(flag); | 1240 | 690k | formatters_.push_back((std::move(unknown_flag))); | 1241 | 690k | } | 1242 | | // fix issue #1617 (prev char was '!' and should have been treated as funcname flag | 1243 | | // instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some | 1244 | | // message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message" | 1245 | 0 | else { | 1246 | 0 | padding.truncate_ = false; | 1247 | 0 | formatters_.push_back( | 1248 | 0 | details::make_unique<details::source_funcname_formatter<Padder>>(padding)); | 1249 | 0 | unknown_flag->add_ch(flag); | 1250 | 0 | formatters_.push_back((std::move(unknown_flag))); | 1251 | 0 | } | 1252 | | | 1253 | 690k | break; | 1254 | 7.86M | } | 1255 | 7.86M | } |
|
1256 | | |
1257 | | // Extract given pad spec (e.g. %8X, %=8X, %-8!X, %8!X, %=8!X, %-8!X, %+8!X) |
1258 | | // Advance the given it pass the end of the padding spec found (if any) |
1259 | | // Return padding. |
1260 | | SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_( |
1261 | 12.6M | std::string::const_iterator &it, std::string::const_iterator end) { |
1262 | 12.6M | using details::padding_info; |
1263 | 12.6M | using details::scoped_padder; |
1264 | 12.6M | const size_t max_width = 64; |
1265 | 12.6M | if (it == end) { |
1266 | 1.86k | return padding_info{}; |
1267 | 1.86k | } |
1268 | | |
1269 | 12.6M | padding_info::pad_side side; |
1270 | 12.6M | switch (*it) { |
1271 | 62.4k | case '-': |
1272 | 62.4k | side = padding_info::pad_side::right; |
1273 | 62.4k | ++it; |
1274 | 62.4k | break; |
1275 | 75.6k | case '=': |
1276 | 75.6k | side = padding_info::pad_side::center; |
1277 | 75.6k | ++it; |
1278 | 75.6k | break; |
1279 | 12.5M | default: |
1280 | 12.5M | side = details::padding_info::pad_side::left; |
1281 | 12.5M | break; |
1282 | 12.6M | } |
1283 | | |
1284 | 12.6M | if (it == end || !std::isdigit(static_cast<unsigned char>(*it))) { |
1285 | 8.73M | return padding_info{}; // no padding if no digit found here |
1286 | 8.73M | } |
1287 | | |
1288 | 3.94M | auto width = static_cast<size_t>(*it) - '0'; |
1289 | 5.96M | for (++it; it != end && std::isdigit(static_cast<unsigned char>(*it)); ++it) { |
1290 | 2.02M | auto digit = static_cast<size_t>(*it) - '0'; |
1291 | 2.02M | width = width * 10 + digit; |
1292 | 2.02M | } |
1293 | | |
1294 | | // search for the optional truncate marker '!' |
1295 | 3.94M | bool truncate; |
1296 | 3.94M | if (it != end && *it == '!') { |
1297 | 553k | truncate = true; |
1298 | 553k | ++it; |
1299 | 3.38M | } else { |
1300 | 3.38M | truncate = false; |
1301 | 3.38M | } |
1302 | 3.94M | return details::padding_info{std::min<size_t>(width, max_width), side, truncate}; |
1303 | 12.6M | } |
1304 | | |
1305 | 26.5k | SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &pattern) { |
1306 | 26.5k | auto end = pattern.end(); |
1307 | 26.5k | std::unique_ptr<details::aggregate_formatter> user_chars; |
1308 | 26.5k | formatters_.clear(); |
1309 | 115M | for (auto it = pattern.begin(); it != end; ++it) { |
1310 | 114M | if (*it == '%') { |
1311 | 12.6M | if (user_chars) // append user chars found so far |
1312 | 4.66M | { |
1313 | 4.66M | formatters_.push_back(std::move(user_chars)); |
1314 | 4.66M | } |
1315 | | |
1316 | 12.6M | auto padding = handle_padspec_(++it, end); |
1317 | | |
1318 | 12.6M | if (it != end) { |
1319 | 12.6M | if (padding.enabled()) { |
1320 | 3.94M | handle_flag_<details::scoped_padder>(*it, padding); |
1321 | 8.73M | } else { |
1322 | 8.73M | handle_flag_<details::null_scoped_padder>(*it, padding); |
1323 | 8.73M | } |
1324 | 12.6M | } else { |
1325 | 3.45k | break; |
1326 | 3.45k | } |
1327 | 12.6M | } else // chars not following the % sign should be displayed as is |
1328 | 102M | { |
1329 | 102M | if (!user_chars) { |
1330 | 4.67M | user_chars = details::make_unique<details::aggregate_formatter>(); |
1331 | 4.67M | } |
1332 | 102M | user_chars->add_ch(*it); |
1333 | 102M | } |
1334 | 114M | } |
1335 | 26.5k | if (user_chars) // append raw chars found so far |
1336 | 6.61k | { |
1337 | 6.61k | formatters_.push_back(std::move(user_chars)); |
1338 | 6.61k | } |
1339 | 26.5k | } |
1340 | | } // namespace spdlog |