Skip to content

Conversation

@Lzw655
Copy link
Collaborator

@Lzw655 Lzw655 commented Jul 3, 2025

Bugfixes:

Copilot AI review requested due to automatic review settings July 3, 2025 06:13
@Lzw655 Lzw655 force-pushed the bugfix/update_cxx_log_trace branch from 976e40e to 814b3f3 Compare July 3, 2025 06:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the logging subsystem to use a C++ RAII-based trace guard, centralizes file-name extraction in C++ code, and updates related logging macros across backends.

  • Replaces C-style trace guard macros with a log_trace_guard class leveraging std::source_location.
  • Renames and consolidates backend macros (STD and ESP) to _IMPL_FUNC and _IMPL variants.
  • Removes the old C implementation of esp_utils_log_extract_file_name and adds a C++ version plus a parseFunctionName helper.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test_apps/main/test_on_cpp.cpp Adds a LogTestClass and exercises the new C++ trace guard.
src/log/impl/esp_utils_log_impl_std.h Refactors STD backend macros (ESP_UTILS_LOG*_IMPL[_FUNC]).
src/log/impl/esp_utils_log_impl_esp.h Refactors ESP backend macros to match the STD pattern.
src/log/impl/esp_utils_log_impl.cpp Introduces C++ esp_utils_log_extract_file_name and parseFunctionName.
src/log/impl/esp_utils_log_impl.c Removes the old C version of esp_utils_log_extract_file_name.
src/log/esp_utils_log.hpp Defines log_trace_guard class and new trace guard macros.
src/log/esp_utils_log.h Updates ESP_UTILS_LOG_LEVEL to use _IMPL macros.
src/esp_utils_versions.h Bumps patch version to 0.2.3.
library.properties Updates library version to 0.2.3.
idf_component.yml Updates component version to "0.2.3".
CHANGELOG.md Adds v0.2.3 entry for the C++ trace guard update.
Comments suppressed due to low confidence (4)

src/log/impl/esp_utils_log_impl.cpp:33

  • The new parseFunctionName function contains non-trivial parsing logic; adding unit tests to cover various signature formats (with/without namespaces and templates) would help prevent regressions.
std::string parseFunctionName(const char *func_name)

src/log/esp_utils_log.hpp:53

  • [nitpick] The log_trace_guard template and its constructors aren’t documented. Consider adding Doxygen comments explaining the TAG parameter and overload behaviors.
template <FixedString TAG>

test_apps/main/test_on_cpp.cpp:15

  • [nitpick] The test helper class LogTestClass has a generic name. Renaming it to reflect its purpose (e.g., TraceGuardTester) could improve readability in larger test suites.
class LogTestClass {

Comment on lines +10 to +21
#define ESP_UTILS_LOGD_IMPL_FUNC(TAG, format, ...) printf("[D][%s]" format "\n", TAG, ##__VA_ARGS__)
#define ESP_UTILS_LOGI_IMPL_FUNC(TAG, format, ...) printf("[I][%s]" format "\n", TAG, ##__VA_ARGS__)
#define ESP_UTILS_LOGW_IMPL_FUNC(TAG, format, ...) printf("[W][%s]" format "\n", TAG, ##__VA_ARGS__)
#define ESP_UTILS_LOGE_IMPL_FUNC(TAG, format, ...) printf("[E][%s]" format "\n", TAG, ##__VA_ARGS__)

#define ESP_UTILS_LOGD_IMPL(TAG, format, ...) ESP_UTILS_LOGD_IMPL_FUNC(TAG, "[%s:%04d](%s): " format, \
esp_utils_log_extract_file_name(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
#define ESP_UTILS_IMPL_LOGI(TAG, format, ...) printf("[I][" TAG "][%s:%04d](%s): " format "\n", \
#define ESP_UTILS_LOGI_IMPL(TAG, format, ...) ESP_UTILS_LOGI_IMPL_FUNC(TAG, "[%s:%04d](%s): " format, \
esp_utils_log_extract_file_name(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
#define ESP_UTILS_IMPL_LOGW(TAG, format, ...) printf("[W][" TAG "][%s:%04d](%s): " format "\n", \
#define ESP_UTILS_LOGW_IMPL(TAG, format, ...) ESP_UTILS_LOGW_IMPL_FUNC(TAG, "[%s:%04d](%s): " format, \
esp_utils_log_extract_file_name(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
#define ESP_UTILS_IMPL_LOGE(TAG, format, ...) printf("[E][" TAG "][%s:%04d](%s): " format "\n", \
#define ESP_UTILS_LOGE_IMPL(TAG, format, ...) ESP_UTILS_LOGE_IMPL_FUNC(TAG, "[%s:%04d](%s): " format, \
Copy link

Copilot AI Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The pair of macros _IMPL_FUNC and _IMPL can be confusing to maintain. Adding a brief comment or renaming to clarify their distinct roles (format-wrapping vs. tagged invocation) may aid future contributors.

Copilot uses AI. Check for mistakes.
@Lzw655 Lzw655 force-pushed the bugfix/update_cxx_log_trace branch from 55d8bb6 to 322451f Compare July 3, 2025 13:34
@Lzw655 Lzw655 merged commit d0fc176 into master Jul 3, 2025
9 checks passed
@Lzw655 Lzw655 deleted the bugfix/update_cxx_log_trace branch July 3, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants