5
5
#include < string>
6
6
#include < string_view>
7
7
8
+ #if defined(ESP_PLATFORM)
9
+ #include < esp_timer.h>
10
+ #endif
11
+
8
12
#include " format.hpp"
9
13
10
14
namespace espp {
@@ -108,7 +112,7 @@ class Logger {
108
112
auto msg = format (rt_fmt_str, std::forward<Args>(args)...);
109
113
if (include_time_) {
110
114
std::lock_guard<std::mutex> lock (tag_mutex_);
111
- fmt::print (fg (fmt::color::gray), " [{}/D][{:.3f }]: {}\n " , tag_, get_time (), msg);
115
+ fmt::print (fg (fmt::color::gray), " [{}/D][{}]: {}\n " , tag_, get_time (), msg);
112
116
} else {
113
117
std::lock_guard<std::mutex> lock (tag_mutex_);
114
118
fmt::print (fg (fmt::color::gray), " [{}/D]:{}\n " , tag_, msg);
@@ -126,7 +130,7 @@ class Logger {
126
130
auto msg = format (rt_fmt_str, std::forward<Args>(args)...);
127
131
if (include_time_) {
128
132
std::lock_guard<std::mutex> lock (tag_mutex_);
129
- fmt::print (fg (fmt::terminal_color::green), " [{}/I][{:.3f }]: {}\n " , tag_, get_time (), msg);
133
+ fmt::print (fg (fmt::terminal_color::green), " [{}/I][{}]: {}\n " , tag_, get_time (), msg);
130
134
} else {
131
135
std::lock_guard<std::mutex> lock (tag_mutex_);
132
136
fmt::print (fg (fmt::terminal_color::green), " [{}/I]:{}\n " , tag_, msg);
@@ -144,7 +148,7 @@ class Logger {
144
148
auto msg = format (rt_fmt_str, std::forward<Args>(args)...);
145
149
if (include_time_) {
146
150
std::lock_guard<std::mutex> lock (tag_mutex_);
147
- fmt::print (fg (fmt::terminal_color::yellow), " [{}/W][{:.3f }]: {}\n " , tag_, get_time (), msg);
151
+ fmt::print (fg (fmt::terminal_color::yellow), " [{}/W][{}]: {}\n " , tag_, get_time (), msg);
148
152
} else {
149
153
std::lock_guard<std::mutex> lock (tag_mutex_);
150
154
fmt::print (fg (fmt::terminal_color::yellow), " [{}/W]:{}\n " , tag_, msg);
@@ -162,7 +166,7 @@ class Logger {
162
166
auto msg = format (rt_fmt_str, std::forward<Args>(args)...);
163
167
if (include_time_) {
164
168
std::lock_guard<std::mutex> lock (tag_mutex_);
165
- fmt::print (fg (fmt::terminal_color::red), " [{}/E][{:.3f }]: {}\n " , tag_, get_time (), msg);
169
+ fmt::print (fg (fmt::terminal_color::red), " [{}/E][{}]: {}\n " , tag_, get_time (), msg);
166
170
} else {
167
171
std::lock_guard<std::mutex> lock (tag_mutex_);
168
172
fmt::print (fg (fmt::terminal_color::red), " [{}/E]:{}\n " , tag_, msg);
@@ -260,10 +264,19 @@ class Logger {
260
264
* @return time in seconds since the start of the logging system.
261
265
*/
262
266
static auto get_time () {
267
+ #if defined(ESP_PLATFORM)
268
+ // use esp_timer_get_time to get the time in microseconds
269
+ uint64_t time = esp_timer_get_time ();
270
+ uint64_t seconds = time / 1e6f;
271
+ uint64_t milliseconds = (time % 1000000 ) / 1e3f;
272
+ return fmt::format (" {}.{:03}" , seconds, milliseconds);
273
+ #else
263
274
// get the elapsed time since the start of the logging system as floating
264
275
// point seconds
265
276
auto now = std::chrono::steady_clock::now ();
266
- return std::chrono::duration<float >(now - start_time_).count ();
277
+ auto seconds = std::chrono::duration<float >(now - start_time_).count ();
278
+ return fmt::format (" {:.3f}" , seconds);
279
+ #endif
267
280
}
268
281
269
282
/* *
0 commit comments