Skip to content

Commit bb9ea3d

Browse files
authored
Merge pull request #9 from esp-arduino-libs/feat/disable_log_cxx
feat(log): disable CXX-related implementations
2 parents 971e061 + 76dfa09 commit bb9ea3d

9 files changed

+109
-97
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## v0.2.0 - 2025-02-07
4+
5+
### Enhancements:
6+
7+
* feat(log): disable CXX-related implementations
8+
39
## v0.1.2 - 2025-01-23
410

511
### Enhancements:

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ idf_component_register(
55
SRCS ${SRCS}
66
INCLUDE_DIRS ${SRC_DIR}
77
)
8+
9+
target_compile_options(${COMPONENT_LIB}
10+
PUBLIC
11+
-Wno-missing-field-initializers
12+
PRIVATE
13+
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17>
14+
)

Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ menu "ESP Library Utils Configurations"
7373
default n
7474
help
7575
If enabled, the driver will print trace log messages when enter/exit functions, useful for debugging
76-
77-
config ESP_UTILS_CONF_LOG_BUFFER_SIZE
78-
int "Buffer size for formatting messages"
79-
default 256
8076
endmenu
8177

8278
menu "Memory functions"

esp_utils_conf.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -41,11 +41,6 @@
4141

4242
#endif // ESP_UTILS_CONF_LOG_LEVEL
4343

44-
/**
45-
* @brief Log format buffer size
46-
*/
47-
#define ESP_UTILS_CONF_LOG_BUFFER_SIZE (256)
48-
4944
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5045
//////////////////////////////////////////////// Memory Configurations /////////////////////////////////////////////////
5146
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -93,7 +88,7 @@
9388
* 3. Even if the patch version is not consistent, it will not affect normal functionality.
9489
*/
9590
#define ESP_UTILS_CONF_FILE_VERSION_MAJOR 1
96-
#define ESP_UTILS_CONF_FILE_VERSION_MINOR 1
91+
#define ESP_UTILS_CONF_FILE_VERSION_MINOR 2
9792
#define ESP_UTILS_CONF_FILE_VERSION_PATCH 0
9893

9994
// *INDENT-ON*

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.2"
1+
version: "0.2.0"
22
description: esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, checking, and memory.
33
url: https://github.com/esp-arduino-libs/esp-lib-utils
44
repository: https://github.com/esp-arduino-libs/esp-lib-utils.git

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=esp-lib-utils
2-
version=0.1.2
2+
version=0.2.0
33
author=espressif
44
maintainer=espressif
55
sentence=esp-lib-utils is a library designed for ESP SoCs to provide utility functions, including logging, checking, and memory.

micropython.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ target_sources(usermod_esp_lib_utils INTERFACE ${SRCS_C} ${SRCS_CXX} ${MPY_C} ${
1818
# Add the current directory as an include directory.
1919
target_include_directories(usermod_esp_lib_utils INTERFACE ${SRC_DIR} ${MPY_DIR})
2020

21+
# Add compile options. Since the target is not created by `idf_component_register()`, we need to add the `ESP_PLATFORM` define manually.
22+
target_compile_options(usermod_esp_lib_utils
23+
INTERFACE
24+
-Wno-missing-field-initializers -DESP_PLATFORM $<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17>
25+
)
26+
2127
# Link our INTERFACE library to the usermod target.
2228
target_link_libraries(usermod INTERFACE usermod_esp_lib_utils)

src/esp_utils_versions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
/* Library Version */
99
#define ESP_UTILS_VERSION_MAJOR 0
10-
#define ESP_UTILS_VERSION_MINOR 1
11-
#define ESP_UTILS_VERSION_PATCH 2
10+
#define ESP_UTILS_VERSION_MINOR 2
11+
#define ESP_UTILS_VERSION_PATCH 0
1212

1313
/* File `esp_utils_conf.h` */
1414
#define ESP_UTILS_CONF_VERSION_MAJOR 1
15-
#define ESP_UTILS_CONF_VERSION_MINOR 1
15+
#define ESP_UTILS_CONF_VERSION_MINOR 2
1616
#define ESP_UTILS_CONF_VERSION_PATCH 0

src/log/esp_utils_log.h

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,75 @@
1111
#define ESP_UTILS_LOG_TAG "Utils"
1212
#endif
1313

14-
#ifdef __cplusplus
15-
16-
#include <cstdio>
17-
#include <cstdarg>
18-
#include <cstring>
19-
#include <functional>
20-
#include <mutex>
21-
22-
extern "C" const char *esp_utils_log_extract_file_name(const char *file_path);
23-
24-
namespace esp_utils {
25-
26-
/**
27-
* Class to handle logging
28-
*/
29-
class Log {
30-
public:
31-
// Singleton pattern: Get the unique instance of the class
32-
static Log &getInstance()
33-
{
34-
static Log instance;
35-
return instance;
36-
}
37-
38-
// Templates and conditional compilation: Filter logs by different levels
39-
template <int level>
40-
void print(const char *file, int line, const char *func, const char *format, ...)
41-
{
42-
// Logs below the global level will not be compiled
43-
if constexpr (level >= ESP_UTILS_CONF_LOG_LEVEL) {
44-
// Mutex to avoid interleaved log messages
45-
std::lock_guard<std::mutex> lock(_mutex);
46-
// Use variadic arguments for formatted output
47-
va_list args;
48-
va_start(args, format);
49-
vsnprintf(_buffer, sizeof(_buffer), format, args);
50-
va_end(args);
51-
// Output log message
52-
printf(
53-
"[%c][%s][%s:%04d](%s): %s\n", logLevelToChar(level), ESP_UTILS_LOG_TAG,
54-
esp_utils_log_extract_file_name(file), line, func, _buffer
55-
);
56-
}
57-
}
58-
59-
private:
60-
Log() = default;
61-
62-
// Convert log level to string
63-
static constexpr char logLevelToChar(int level)
64-
{
65-
switch (level) {
66-
case ESP_UTILS_LOG_LEVEL_DEBUG: return 'D';
67-
case ESP_UTILS_LOG_LEVEL_INFO: return 'I';
68-
case ESP_UTILS_LOG_LEVEL_WARNING: return 'W';
69-
case ESP_UTILS_LOG_LEVEL_ERROR: return 'E';
70-
default: break;
71-
}
72-
return ' ';
73-
}
74-
75-
char _buffer[ESP_UTILS_CONF_LOG_BUFFER_SIZE];
76-
std::mutex _mutex;
77-
};
78-
79-
} // namespace esp_utils
14+
// #include <cstdio>
15+
// #include <cstdarg>
16+
// #include <cstring>
17+
// #include <functional>
18+
// #include <mutex>
19+
20+
// extern "C" const char *esp_utils_log_extract_file_name(const char *file_path);
21+
22+
// namespace esp_utils {
23+
24+
// /**
25+
// * Class to handle logging
26+
// */
27+
// class Log {
28+
// public:
29+
// // Singleton pattern: Get the unique instance of the class
30+
// static Log &getInstance()
31+
// {
32+
// static Log instance;
33+
// return instance;
34+
// }
35+
36+
// // Templates and conditional compilation: Filter logs by different levels
37+
// template <int level>
38+
// void print(const char *file, int line, const char *func, const char *format, ...)
39+
// {
40+
// // Logs below the global level will not be compiled
41+
// if constexpr (level >= ESP_UTILS_CONF_LOG_LEVEL) {
42+
// // Mutex to avoid interleaved log messages
43+
// std::lock_guard<std::mutex> lock(_mutex);
44+
// // Use variadic arguments for formatted output
45+
// va_list args;
46+
// va_start(args, format);
47+
// vsnprintf(_buffer, sizeof(_buffer), format, args);
48+
// va_end(args);
49+
// // Output log message
50+
// printf(
51+
// "[%c][%s][%s:%04d](%s): %s\n", logLevelToChar(level), ESP_UTILS_LOG_TAG,
52+
// esp_utils_log_extract_file_name(file), line, func, _buffer
53+
// );
54+
// }
55+
// }
56+
57+
// private:
58+
// Log() = default;
59+
60+
// // Convert log level to string
61+
// static constexpr char logLevelToChar(int level)
62+
// {
63+
// switch (level) {
64+
// case ESP_UTILS_LOG_LEVEL_DEBUG: return 'D';
65+
// case ESP_UTILS_LOG_LEVEL_INFO: return 'I';
66+
// case ESP_UTILS_LOG_LEVEL_WARNING: return 'W';
67+
// case ESP_UTILS_LOG_LEVEL_ERROR: return 'E';
68+
// default: break;
69+
// }
70+
// return ' ';
71+
// }
72+
73+
// char _buffer[ESP_UTILS_CONF_LOG_BUFFER_SIZE];
74+
// std::mutex _mutex;
75+
// };
76+
77+
// } // namespace esp_utils
8078

8179
/**
8280
* Macros to simplify logging calls
8381
*/
82+
/*
8483
#define ESP_UTILS_LOGD(format, ...) \
8584
esp_utils::Log::getInstance().print<ESP_UTILS_LOG_LEVEL_DEBUG>(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
8685
#define ESP_UTILS_LOGI(format, ...) \
@@ -89,25 +88,21 @@ class Log {
8988
esp_utils::Log::getInstance().print<ESP_UTILS_LOG_LEVEL_WARNING>(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
9089
#define ESP_UTILS_LOGE(format, ...) \
9190
esp_utils::Log::getInstance().print<ESP_UTILS_LOG_LEVEL_ERROR>(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
92-
93-
/**
94-
* Micros to log trace of function calls
95-
*/
96-
#if ESP_UTILS_CONF_ENABLE_LOG_TRACE
97-
#define ESP_UTILS_LOG_TRACE_ENTER_WITH_THIS() ESP_UTILS_LOGD("(@%p) Enter", this)
98-
#define ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS() ESP_UTILS_LOGD("(@%p) Exit", this)
99-
#else
100-
#define ESP_UTILS_LOG_TRACE_ENTER_WITH_THIS()
101-
#define ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS()
102-
#endif
103-
104-
#else
91+
*/
10592

10693
#include <stdio.h>
10794
#include <string.h>
10895

96+
#ifdef __cplusplus
97+
extern "C" {
98+
#endif
99+
109100
const char *esp_utils_log_extract_file_name(const char *file_path);
110101

102+
#ifdef __cplusplus
103+
}
104+
#endif
105+
111106
#define ESP_UTILS_IMPL_LOGD(format, ...) printf("[D][" ESP_UTILS_LOG_TAG "][%s:%04d](%s): " format "\n", \
112107
esp_utils_log_extract_file_name(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
113108
#define ESP_UTILS_IMPL_LOGI(format, ...) printf("[I][" ESP_UTILS_LOG_TAG "][%s:%04d](%s): " format "\n", \
@@ -137,8 +132,6 @@ const char *esp_utils_log_extract_file_name(const char *file_path);
137132
#define ESP_UTILS_LOGW(format, ...) ESP_UTILS_LOG_LEVEL_LOCAL(ESP_UTILS_LOG_LEVEL_WARNING, format, ##__VA_ARGS__)
138133
#define ESP_UTILS_LOGE(format, ...) ESP_UTILS_LOG_LEVEL_LOCAL(ESP_UTILS_LOG_LEVEL_ERROR, format, ##__VA_ARGS__)
139134

140-
#endif // __cplusplus
141-
142135
/**
143136
* Micros to log trace of function calls
144137
*/
@@ -149,3 +142,12 @@ const char *esp_utils_log_extract_file_name(const char *file_path);
149142
#define ESP_UTILS_LOG_TRACE_ENTER()
150143
#define ESP_UTILS_LOG_TRACE_EXIT()
151144
#endif
145+
#ifdef __cplusplus
146+
#if ESP_UTILS_CONF_ENABLE_LOG_TRACE
147+
#define ESP_UTILS_LOG_TRACE_ENTER_WITH_THIS() ESP_UTILS_LOGD("(@%p) Enter", this)
148+
#define ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS() ESP_UTILS_LOGD("(@%p) Exit", this)
149+
#else
150+
#define ESP_UTILS_LOG_TRACE_ENTER_WITH_THIS()
151+
#define ESP_UTILS_LOG_TRACE_EXIT_WITH_THIS()
152+
#endif
153+
#endif

0 commit comments

Comments
 (0)