Skip to content

Commit aecf43f

Browse files
committed
feat(logger): Update to use esp_log_timestamp so that timestamp value matches ESP_LOG timestamps
1 parent 8803547 commit aecf43f

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

components/logger/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
if (ESP_PLATFORM)
22
# set component requirements for ESP32
3-
set(COMPONENT_REQUIRES "format esp_timer")
3+
set(COMPONENT_REQUIRES "format esp_timer log")
44
else()
55
# set component requirements for generic
66
set(COMPONENT_REQUIRES "format")

components/logger/example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set(EXTRA_COMPONENT_DIRS
1212

1313
set(
1414
COMPONENTS
15-
"main esptool_py logger"
15+
"main esptool_py logger esp_vfs_console"
1616
CACHE STRING
1717
"List of components to include"
1818
)

components/logger/include/logger.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#include <string_view>
88

99
#if defined(ESP_PLATFORM)
10-
#include <esp_timer.h>
10+
// include sdkconfig before the rest
1111
#include <sdkconfig.h>
12+
13+
// esp-idf includes
14+
#include <esp_log_timestamp.h>
15+
#include <esp_timer.h>
1216
#endif
1317

1418
#include "format.hpp"
@@ -419,10 +423,10 @@ rate limit. @note Only calls that have _rate_limited suffixed will be rate limit
419423
*/
420424
static std::string get_time() {
421425
#if defined(ESP_PLATFORM)
422-
// use esp_timer_get_time to get the time in microseconds
423-
uint64_t time = esp_timer_get_time();
424-
uint64_t seconds = time / 1e6f;
425-
uint64_t milliseconds = (time % 1000000) / 1e3f;
426+
// use esp_log_timestamp to get the time in milliseconds
427+
uint64_t time = esp_log_timestamp();
428+
uint64_t seconds = time / 1e3f;
429+
uint64_t milliseconds = (time % 1'000);
426430
return fmt::format("{}.{:03}", seconds, milliseconds);
427431
#else
428432
// get the elapsed time since the start of the logging system as floating

0 commit comments

Comments
 (0)