Skip to content

Commit ec990f4

Browse files
author
Konstantin Kondrashov
committed
Merge branch 'feature/logv2_2' into 'master'
feat(log): Log v2 Closes IDF-245, IDFGH-3855, IDF-2956, IDF-7883, and IDFGH-13066 See merge request espressif/esp-idf!31128
2 parents 4a07179 + 0e5a11c commit ec990f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2446
-379
lines changed

components/bootloader/Kconfig.log

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
menu "Log"
22

3+
choice BOOTLOADER_LOG_VERSION
4+
prompt "Log version"
5+
help
6+
Select the log version to be used by the ESP log component.
7+
The app log version (CONFIG_LOG_VERSION) controls the version used in the bootloader,
8+
preventing the selection of different versions.
9+
For description of V1 and V2 see CONFIG_LOG_VERSION.
10+
11+
config BOOTLOADER_LOG_VERSION_1
12+
bool "V1" if LOG_VERSION_1
13+
config BOOTLOADER_LOG_VERSION_2
14+
bool "V2" if LOG_VERSION_2
15+
endchoice
16+
17+
config BOOTLOADER_LOG_VERSION
18+
int
19+
default 1 if BOOTLOADER_LOG_VERSION_1
20+
default 2 if BOOTLOADER_LOG_VERSION_2
21+
help
22+
This configuration sets the log version number based on the chosen log version.
23+
324
choice BOOTLOADER_LOG_LEVEL
425
bool "Bootloader log verbosity"
526
default BOOTLOADER_LOG_LEVEL_INFO

components/bootloader/Kconfig.log.format

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ menu "Format"
33
config BOOTLOADER_LOG_COLORS
44
bool "Color"
55
default n
6+
select BOOTLOADER_LOG_COLORS_SUPPORT if BOOTLOADER_LOG_VERSION_2
67
help
7-
Use ANSI terminal colors in log output
8-
Enable ANSI terminal color codes.
8+
Enable ANSI terminal color codes. Logs (info, errors, warnings) will contain color codes.
99
In order to view these, your terminal program must support ANSI color codes.
1010

11+
config BOOTLOADER_LOG_COLORS_SUPPORT
12+
bool "Allow enabling color output at run time"
13+
depends on BOOTLOADER_LOG_VERSION_2
14+
default n
15+
help
16+
Enables support for color codes in the esp_log() function. If CONFIG_LOG_COLORS is enabled, this option
17+
is always active. If CONFIG_LOG_COLORS is disabled, this option allows you to still handle color codes
18+
in specific files by defining ESP_LOG_COLOR_DISABLED as 0 before including esp_log.h.
19+
20+
Note that enabling this option may slightly increase RAM/FLASH usage due to additional color handling
21+
functionality. It provides flexibility to manage color output even when CONFIG_LOG_COLORS is turned off.
22+
1123
choice BOOTLOADER_LOG_TIMESTAMP_SOURCE
1224
prompt "Timestamp"
1325
default BOOTLOADER_LOG_TIMESTAMP_SOURCE_CPU_TICKS
@@ -28,11 +40,25 @@ menu "Format"
2840

2941
config BOOTLOADER_LOG_TIMESTAMP_SOURCE_NONE
3042
bool "None"
31-
depends on NO_SYMBOL # hide it now, turn it on final MR
43+
depends on BOOTLOADER_LOG_VERSION_2
3244

3345
config BOOTLOADER_LOG_TIMESTAMP_SOURCE_CPU_TICKS
3446
bool "Milliseconds Since Boot"
47+
select BOOTLOADER_LOG_TIMESTAMP_SUPPORT if BOOTLOADER_LOG_VERSION_2
3548

3649
endchoice # BOOTLOADER_LOG_TIMESTAMP_SOURCE
3750

51+
config BOOTLOADER_LOG_TIMESTAMP_SUPPORT
52+
bool "Allow enabling timestamp output at run time"
53+
depends on BOOTLOADER_LOG_VERSION_2
54+
default y
55+
help
56+
Enables support for timestamp in the esp_log() function.
57+
If CONFIG_LOG_TIMESTAMP_SOURCE_NONE, this option allows you to still handle timestamp
58+
in specific files by defining ESP_LOG_TIMESTAMP_DISABLED as 0 before including esp_log.h.
59+
60+
Note that enabling this option may slightly increase RAM/FLASH usage due to additional timestamp handling
61+
functionality. It provides flexibility to manage timestamp output even when
62+
CONFIG_LOG_TIMESTAMP_SOURCE_NONE.
63+
3864
endmenu

components/esp_system/startup_funcs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "esp_err.h"
1313
#include "esp_check.h"
1414
#include "esp_system.h"
15+
#include "esp_private/log_util.h"
1516
#include "esp_log.h"
17+
#include "esp_private/cache_utils.h"
1618
#include "spi_flash_mmap.h"
1719
#include "esp_flash_internal.h"
1820
#if CONFIG_NEWLIB_ENABLED
@@ -107,6 +109,8 @@ ESP_SYSTEM_INIT_FN(init_flash, CORE, BIT(0), 130)
107109
#if CONFIG_SPI_FLASH_BROWNOUT_RESET
108110
spi_flash_needs_reset_check();
109111
#endif // CONFIG_SPI_FLASH_BROWNOUT_RESET
112+
// The log library will call the registered callback function to check if the cache is disabled.
113+
esp_log_util_set_cache_enabled_cb(spi_flash_cache_enabled);
110114
return ESP_OK;
111115
}
112116
#endif // !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP

components/log/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ endif()
1313

1414
set(srcs "src/${system_target}/log_timestamp.c"
1515
"src/log_timestamp_common.c"
16-
"src/${system_target}/log_lock.c")
16+
"src/${system_target}/log_lock.c"
17+
"src/buffer/log_buffers.c"
18+
"src/${system_target}/util.c"
19+
"src/util.c"
20+
"src/log_print.c"
21+
"src/log.c")
22+
1723
set(priv_requires "")
1824

1925
if(NOT non_os_build)
2026
list(APPEND priv_requires soc hal esp_hw_support)
2127

2228
list(APPEND srcs "src/os/log_write.c")
2329

24-
# Buffer APIs call ESP_LOG_LEVEL -> esp_log_write, which can not used in bootloader.
25-
list(APPEND srcs "src/buffer/log_buffers.c"
26-
"src/util.c")
27-
2830
list(APPEND srcs "src/log_level/log_level.c"
2931
"src/log_level/tag_log_level/tag_log_level.c")
3032

components/log/Kconfig

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
11
menu "Log"
22

3+
choice LOG_VERSION
4+
prompt "Log version"
5+
default LOG_VERSION_1
6+
help
7+
Select the log version to be used by the ESP log component.
8+
9+
- "V1": This version integrates log formatting into the format string provided by the user.
10+
Logs are processed and formatted during compile time, leading to a larger binary file.
11+
Example: ESP_LOGI("boot", "chip revision: v%d.%d", major, minor);
12+
Output: I (56) boot: chip revision: v3.0
13+
Note: Log strings are stored in Flash with added formatting characters.
14+
Format string on flash: "[0;32mI (%lu) %s: chip revision: v%d.%d [0m"
15+
16+
- "V2": This version centralizes log formatting within the esp_log() function.
17+
User-supplied format strings are stored without added formatting, reducing binary size.
18+
Example: ESP_LOGI("boot", "chip revision: v%d.%d", major, minor);
19+
Output: I (56) boot: chip revision: v3.0
20+
Note: This version supports runtime configuration of formatting and is more flexible,
21+
logging from constrained environments (ex.: ISR, Startup, Cache disabled).
22+
It may consumes a bit more stack and affect performance.
23+
Format string on flash: "chip revision: v%d.%d"
24+
25+
Use V1 for minimal stack usage and simpler implementation.
26+
Use V2 for smaller binary sizes, more flexible log formatting, and advanced features like disabling
27+
colors or timestamps.
28+
29+
config LOG_VERSION_1
30+
bool "V1"
31+
help
32+
Select this option to use Log V1. Recommended for projects with strict stack constraints
33+
or that prioritize performance over flexibility.
34+
35+
config LOG_VERSION_2
36+
bool "V2"
37+
help
38+
Select this option to use Log V2. Recommended for projects that require smaller binaries,
39+
runtime log formatting configuration, or advanced logging features.
40+
endchoice
41+
42+
config LOG_VERSION
43+
int
44+
default 1 if LOG_VERSION_1
45+
default 2 if LOG_VERSION_2
46+
help
47+
This configuration sets the log version number based on the chosen log version.
48+
349
orsource "./Kconfig.level"
450

551
orsource "./Kconfig.format"

components/log/Kconfig.format

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ menu "Format"
33
config LOG_COLORS
44
bool "Color"
55
default n
6+
select LOG_COLORS_SUPPORT if LOG_VERSION_2
67
help
7-
Enable ANSI terminal color codes.
8+
Enable ANSI terminal color codes. Logs (info, errors, warnings) will contain color codes.
89
In order to view these, your terminal program must support ANSI color codes.
910

11+
config LOG_COLORS_SUPPORT
12+
bool "Allow enabling color output at run time"
13+
depends on LOG_VERSION_2
14+
default n
15+
help
16+
Enables support for color codes in the esp_log() function. If CONFIG_LOG_COLORS is enabled, this option
17+
is always active. If CONFIG_LOG_COLORS is disabled, this option allows you to still handle color codes
18+
in specific files by defining ESP_LOG_COLOR_DISABLED as 0 before including esp_log.h.
19+
20+
Note that enabling this option may slightly increase IRAM usage due to additional color handling
21+
functionality. It provides flexibility to manage color output even when CONFIG_LOG_COLORS is turned off.
22+
1023
choice LOG_TIMESTAMP_SOURCE
1124
prompt "Timestamp"
1225
default LOG_TIMESTAMP_SOURCE_RTOS
@@ -33,24 +46,49 @@ menu "Format"
3346
- "System time (YY-MM-DD HH:MM:SS.sss)" it is the same as the above,
3447
but also prints the date as well.
3548

49+
- "Unix time in milliseconds" is the same as the two above,
50+
but in Unix time format and in milliseconds.
51+
e.g. (1718795571035).
52+
3653
- NOTE: Currently this will not get used in logging from binary blobs
3754
(i.e WiFi & Bluetooth libraries), these will always print
3855
milliseconds since boot.
3956

4057
config LOG_TIMESTAMP_SOURCE_NONE
4158
bool "None"
42-
depends on NO_SYMBOL # hide it now, turn it on final MR
59+
depends on LOG_VERSION_2
4360

4461
config LOG_TIMESTAMP_SOURCE_RTOS
4562
bool "Milliseconds Since Boot"
63+
select LOG_TIMESTAMP_SUPPORT if LOG_VERSION_2
4664

4765
config LOG_TIMESTAMP_SOURCE_SYSTEM
4866
bool "System Time (HH:MM:SS.sss)"
67+
select LOG_TIMESTAMP_SUPPORT if LOG_VERSION_2
4968

5069
config LOG_TIMESTAMP_SOURCE_SYSTEM_FULL
5170
bool "System Time (YY-MM-DD HH:MM:SS.sss)"
52-
depends on NO_SYMBOL # hide it now, turn it on final MR
71+
select LOG_TIMESTAMP_SUPPORT if LOG_VERSION_2
72+
depends on LOG_VERSION_2
73+
74+
config LOG_TIMESTAMP_SOURCE_UNIX
75+
bool "Unix time in milliseconds"
76+
select LOG_TIMESTAMP_SUPPORT if LOG_VERSION_2
77+
depends on LOG_VERSION_2
5378

5479
endchoice # LOG_TIMESTAMP_SOURCE
5580

81+
config LOG_TIMESTAMP_SUPPORT
82+
bool "Allow enabling timestamp output at run time"
83+
depends on LOG_VERSION_2
84+
default y
85+
help
86+
Enables support for timestamp in the esp_log() function.
87+
If CONFIG_LOG_TIMESTAMP_SOURCE_NONE, this option allows you to still handle timestamp
88+
in specific files by defining ESP_LOG_TIMESTAMP_DISABLED as 0 before including esp_log.h.
89+
90+
Note that enabling this option may slightly increase IRAM usage due to additional timestamp handling
91+
functionality. It provides flexibility to manage timestamp output even when
92+
CONFIG_LOG_TIMESTAMP_SOURCE_NONE.
93+
5694
endmenu

0 commit comments

Comments
 (0)