Skip to content

Commit

Permalink
Merge branch 'feature/log_level_check_refactoring' into 'master'
Browse files Browse the repository at this point in the history
feat(log): Refactoring tag level check APIs

Closes IDF-9083, IDF-7919, and IDFGH-6947

See merge request espressif/esp-idf!29331
  • Loading branch information
KonstantinKondrashov committed May 17, 2024
2 parents 2716976 + c3b0418 commit 712005c
Show file tree
Hide file tree
Showing 34 changed files with 1,338 additions and 567 deletions.
23 changes: 18 additions & 5 deletions components/log/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(priv_requires "")
if(BOOTLOADER_BUILD)
list(APPEND srcs "log_noos.c")
else()
list(APPEND srcs "log.c")
list(APPEND srcs "src/os/log_write.c")

if(${target} STREQUAL "linux")
list(APPEND srcs "log_linux.c")
Expand All @@ -18,10 +18,23 @@ else()
# Buffer APIs call ESP_LOG_LEVEL -> esp_log_write, which can not used in bootloader.
list(APPEND srcs "src/buffer/log_buffers.c"
"src/util.c")

list(APPEND srcs "src/log_level/log_level.c"
"src/log_level/tag_log_level/tag_log_level.c")

if(CONFIG_LOG_TAG_LEVEL_IMPL_LINKED_LIST OR CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_AND_LINKED_LIST)
list(APPEND srcs "src/log_level/tag_log_level/linked_list/log_linked_list.c")
endif()

if(CONFIG_LOG_TAG_LEVEL_CACHE_ARRAY)
list(APPEND srcs "src/log_level/tag_log_level/cache/log_array.c")
elseif(CONFIG_LOG_TAG_LEVEL_CACHE_BINARY_MIN_HEAP)
list(APPEND srcs "src/log_level/tag_log_level/cache/log_binary_heap.c")
endif()
endif()

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "include/esp_private"
LDFRAGMENTS linker.lf
PRIV_REQUIRES ${priv_requires})
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "include/esp_private"
LDFRAGMENTS linker.lf
PRIV_REQUIRES ${priv_requires})
136 changes: 3 additions & 133 deletions components/log/Kconfig
Original file line number Diff line number Diff line change
@@ -1,137 +1,7 @@
menu "Log output"
menu "Log"

choice LOG_DEFAULT_LEVEL
bool "Default log verbosity"
default LOG_DEFAULT_LEVEL_INFO
help
Specify how much output to see in logs by default.
You can set lower verbosity level at runtime using
esp_log_level_set function.
orsource "./Kconfig.level"

By default, this setting limits which log statements
are compiled into the program. For example, selecting
"Warning" would mean that changing log level to "Debug"
at runtime will not be possible. To allow increasing log
level above the default at runtime, see the next option.

config LOG_DEFAULT_LEVEL_NONE
bool "No output"
config LOG_DEFAULT_LEVEL_ERROR
bool "Error"
config LOG_DEFAULT_LEVEL_WARN
bool "Warning"
config LOG_DEFAULT_LEVEL_INFO
bool "Info"
config LOG_DEFAULT_LEVEL_DEBUG
bool "Debug"
config LOG_DEFAULT_LEVEL_VERBOSE
bool "Verbose"
endchoice

config LOG_DEFAULT_LEVEL
int
default 0 if LOG_DEFAULT_LEVEL_NONE
default 1 if LOG_DEFAULT_LEVEL_ERROR
default 2 if LOG_DEFAULT_LEVEL_WARN
default 3 if LOG_DEFAULT_LEVEL_INFO
default 4 if LOG_DEFAULT_LEVEL_DEBUG
default 5 if LOG_DEFAULT_LEVEL_VERBOSE

choice LOG_MAXIMUM_LEVEL
bool "Maximum log verbosity"
default LOG_MAXIMUM_EQUALS_DEFAULT
help
This config option sets the highest log verbosity that it's possible to select
at runtime by calling esp_log_level_set(). This level may be higher than
the default verbosity level which is set when the app starts up.

This can be used enable debugging output only at a critical point, for a particular
tag, or to minimize startup time but then enable more logs once the firmware has
loaded.

Note that increasing the maximum available log level will increase the firmware
binary size.

This option only applies to logging from the app, the bootloader log level is
fixed at compile time to the separate "Bootloader log verbosity" setting.

config LOG_MAXIMUM_EQUALS_DEFAULT
bool "Same as default"
config LOG_MAXIMUM_LEVEL_ERROR
bool "Error"
depends on LOG_DEFAULT_LEVEL < 1
config LOG_MAXIMUM_LEVEL_WARN
bool "Warning"
depends on LOG_DEFAULT_LEVEL < 2
config LOG_MAXIMUM_LEVEL_INFO
bool "Info"
depends on LOG_DEFAULT_LEVEL < 3
config LOG_MAXIMUM_LEVEL_DEBUG
bool "Debug"
depends on LOG_DEFAULT_LEVEL < 4
config LOG_MAXIMUM_LEVEL_VERBOSE
bool "Verbose"
depends on LOG_DEFAULT_LEVEL < 5
endchoice

config LOG_MAXIMUM_LEVEL
int
default LOG_DEFAULT_LEVEL if LOG_MAXIMUM_EQUALS_DEFAULT
default 0 if LOG_MAXIMUM_LEVEL_NONE
default 1 if LOG_MAXIMUM_LEVEL_ERROR
default 2 if LOG_MAXIMUM_LEVEL_WARN
default 3 if LOG_MAXIMUM_LEVEL_INFO
default 4 if LOG_MAXIMUM_LEVEL_DEBUG
default 5 if LOG_MAXIMUM_LEVEL_VERBOSE

config LOG_MASTER_LEVEL
bool "Enable global master log level"
default "n"
help
Enables an additional global "master" log level check that occurs
before a log tag cache lookup. This is useful if you want to
compile in a lot of logs that are selectable at runtime, but avoid the
performance hit during periods where you don't want log output. Examples
include remote log forwarding, or disabling logs during a time-critical
or CPU-intensive section and re-enabling them later. Results in
larger program size depending on number of logs compiled in.

If enabled, defaults to LOG_DEFAULT_LEVEL and can be set using
esp_log_set_level_master().
This check takes precedence over ESP_LOG_LEVEL_LOCAL.

config LOG_COLORS
bool "Use ANSI terminal colors in log output"
default "y"
help
Enable ANSI terminal color codes in bootloader output.

In order to view these, your terminal program must support ANSI color codes.

choice LOG_TIMESTAMP_SOURCE
prompt "Log Timestamps"
default LOG_TIMESTAMP_SOURCE_RTOS
help
Choose what sort of timestamp is displayed in the log output:

- Milliseconds since boot is calulated from the RTOS tick count multiplied
by the tick period. This time will reset after a software reboot.
e.g. (90000)

- System time is taken from POSIX time functions which use the chip's
RTC and high resoultion timers to maintain an accurate time. The system time is
initialized to 0 on startup, it can be set with an SNTP sync, or with
POSIX time functions. This time will not reset after a software reboot.
e.g. (00:01:30.000)

- NOTE: Currently this will not get used in logging from binary blobs
(i.e WiFi & Bluetooth libraries), these will always print
milliseconds since boot.

config LOG_TIMESTAMP_SOURCE_RTOS
bool "Milliseconds Since Boot"
config LOG_TIMESTAMP_SOURCE_SYSTEM
bool "System Time"
endchoice
orsource "./Kconfig.format"

endmenu
36 changes: 36 additions & 0 deletions components/log/Kconfig.format
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
menu "Format"

config LOG_COLORS
bool "Color"
default y
help
Enable ANSI terminal color codes.
In order to view these, your terminal program must support ANSI color codes.

choice LOG_TIMESTAMP_SOURCE
prompt "Timestamp"
default LOG_TIMESTAMP_SOURCE_RTOS
help
Choose what sort of timestamp is displayed in the log output:

- "Milliseconds since boot" is calculated from the RTOS tick count multiplied
by the tick period. This time will reset after a software reboot.
e.g. (90000)

- "System time" is taken from POSIX time functions which use the chip's
RTC and high resolution timers to maintain an accurate time. The system time is
initialized to 0 on startup, it can be set with an SNTP sync, or with
POSIX time functions. This time will not reset after a software reboot.
e.g. (00:01:30.000)

- NOTE: Currently this will not get used in logging from binary blobs
(i.e WiFi & Bluetooth libraries), these will always print
milliseconds since boot.

config LOG_TIMESTAMP_SOURCE_RTOS
bool "Milliseconds Since Boot"
config LOG_TIMESTAMP_SOURCE_SYSTEM
bool "System Time"
endchoice # LOG_TIMESTAMP_SOURCE

endmenu
90 changes: 90 additions & 0 deletions components/log/Kconfig.level
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
menu "Log Level"

choice LOG_DEFAULT_LEVEL
bool "Default log verbosity"
default LOG_DEFAULT_LEVEL_INFO
help
Specify how much output to see in logs by default.
You can set lower verbosity level at runtime using
esp_log_level_set() function if LOG_DYNAMIC_LEVEL_CONTROL
is enabled.

By default, this setting limits which log statements
are compiled into the program. For example, selecting
"Warning" would mean that changing log level to "Debug"
at runtime will not be possible. To allow increasing log
level above the default at runtime, see the next option.

config LOG_DEFAULT_LEVEL_NONE
bool "No output"
config LOG_DEFAULT_LEVEL_ERROR
bool "Error"
config LOG_DEFAULT_LEVEL_WARN
bool "Warning"
config LOG_DEFAULT_LEVEL_INFO
bool "Info"
config LOG_DEFAULT_LEVEL_DEBUG
bool "Debug"
config LOG_DEFAULT_LEVEL_VERBOSE
bool "Verbose"
endchoice

config LOG_DEFAULT_LEVEL
int
default 0 if LOG_DEFAULT_LEVEL_NONE
default 1 if LOG_DEFAULT_LEVEL_ERROR
default 2 if LOG_DEFAULT_LEVEL_WARN
default 3 if LOG_DEFAULT_LEVEL_INFO
default 4 if LOG_DEFAULT_LEVEL_DEBUG
default 5 if LOG_DEFAULT_LEVEL_VERBOSE

choice LOG_MAXIMUM_LEVEL
bool "Maximum log verbosity"
default LOG_MAXIMUM_EQUALS_DEFAULT
help
This config option sets the highest log verbosity that it's possible to select
at runtime by calling esp_log_level_set(). This level may be higher than
the default verbosity level which is set when the app starts up.

This can be used enable debugging output only at a critical point, for a particular
tag, or to minimize startup time but then enable more logs once the firmware has
loaded.

Note that increasing the maximum available log level will increase the firmware
binary size.

This option only applies to logging from the app, the bootloader log level is
fixed at compile time to the separate "Bootloader log verbosity" setting.

config LOG_MAXIMUM_EQUALS_DEFAULT
bool "Same as default"
config LOG_MAXIMUM_LEVEL_ERROR
bool "Error"
depends on LOG_DEFAULT_LEVEL < 1
config LOG_MAXIMUM_LEVEL_WARN
bool "Warning"
depends on LOG_DEFAULT_LEVEL < 2
config LOG_MAXIMUM_LEVEL_INFO
bool "Info"
depends on LOG_DEFAULT_LEVEL < 3
config LOG_MAXIMUM_LEVEL_DEBUG
bool "Debug"
depends on LOG_DEFAULT_LEVEL < 4
config LOG_MAXIMUM_LEVEL_VERBOSE
bool "Verbose"
depends on LOG_DEFAULT_LEVEL < 5
endchoice

config LOG_MAXIMUM_LEVEL
int
default LOG_DEFAULT_LEVEL if LOG_MAXIMUM_EQUALS_DEFAULT
default 0 if LOG_MAXIMUM_LEVEL_NONE
default 1 if LOG_MAXIMUM_LEVEL_ERROR
default 2 if LOG_MAXIMUM_LEVEL_WARN
default 3 if LOG_MAXIMUM_LEVEL_INFO
default 4 if LOG_MAXIMUM_LEVEL_DEBUG
default 5 if LOG_MAXIMUM_LEVEL_VERBOSE

orsource "./Kconfig.level_settings"

endmenu
Loading

0 comments on commit 712005c

Please sign in to comment.