Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (ESP_PLATFORM)
# set component requirements for ESP32
set(COMPONENT_REQUIRES "format esp_timer")
set(COMPONENT_REQUIRES "format esp_timer log")
else()
# set component requirements for generic
set(COMPONENT_REQUIRES "format")
Expand Down
4 changes: 3 additions & 1 deletion components/logger/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ set(EXTRA_COMPONENT_DIRS

set(
COMPONENTS
"main esptool_py logger"
# NOTE: we add esp_vfs_console to be able to see the log output on the console
# if we are running on ESP32-S2 and have enabled USB-CDC console output
"main esptool_py logger esp_vfs_console"
CACHE STRING
"List of components to include"
)
Expand Down
14 changes: 9 additions & 5 deletions components/logger/include/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
#include <string_view>

#if defined(ESP_PLATFORM)
#include <esp_timer.h>
// include sdkconfig before the rest
#include <sdkconfig.h>

// esp-idf includes
#include <esp_log_timestamp.h>
#include <esp_timer.h>
#endif

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