From fa570cc3a2763e78ffb151c5502b5b35bcd1bcda Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Fri, 11 Oct 2024 18:50:49 +0530 Subject: [PATCH] Revert "esp32-fix-empty-logs(#35939)" (#36035) * Revert "esp32-fix-empty-logs(#35939) (#35965)" This reverts commit 2a19f577b15c9cf1c1433bba14e6fff0d141ed41. * Add comment explaining why printf is used --- src/platform/ESP32/Logging.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/platform/ESP32/Logging.cpp b/src/platform/ESP32/Logging.cpp index 9dfa1d87a145e6..9ad98db789b3d6 100644 --- a/src/platform/ESP32/Logging.cpp +++ b/src/platform/ESP32/Logging.cpp @@ -25,13 +25,16 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) snprintf(tag, sizeof(tag), "chip[%s]", module); tag[sizeof(tag) - 1] = 0; + // We intentionally added the printf statements to ensure we could apply colors to logs redirected to the console. + // The printf statements are not bypassing the log level, rather, they are intentionally designed to print the + // initial and later parts of the log. switch (category) { case kLogCategory_Error: { { - esp_log_write(ESP_LOG_ERROR, tag, LOG_COLOR_E "E (%" PRIu32 ") %s: ", esp_log_timestamp(), tag); + printf(LOG_COLOR_E "E (%" PRIu32 ") %s: ", esp_log_timestamp(), tag); esp_log_writev(ESP_LOG_ERROR, tag, msg, v); - esp_log_write(ESP_LOG_ERROR, tag, LOG_RESET_COLOR "\n"); + printf(LOG_RESET_COLOR "\n"); } } break; @@ -39,18 +42,18 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) case kLogCategory_Progress: default: { { - esp_log_write(ESP_LOG_INFO, tag, LOG_COLOR_I "I (%" PRIu32 ") %s: ", esp_log_timestamp(), tag); + printf(LOG_COLOR_I "I (%" PRIu32 ") %s: ", esp_log_timestamp(), tag); esp_log_writev(ESP_LOG_INFO, tag, msg, v); - esp_log_write(ESP_LOG_INFO, tag, LOG_RESET_COLOR "\n"); + printf(LOG_RESET_COLOR "\n"); } } break; case kLogCategory_Detail: { { - esp_log_write(ESP_LOG_DEBUG, tag, LOG_COLOR_D "D (%" PRIu32 ") %s: ", esp_log_timestamp(), tag); + printf(LOG_COLOR_D "D (%" PRIu32 ") %s: ", esp_log_timestamp(), tag); esp_log_writev(ESP_LOG_DEBUG, tag, msg, v); - esp_log_write(ESP_LOG_DEBUG, tag, LOG_RESET_COLOR "\n"); + printf(LOG_RESET_COLOR "\n"); } } break;