System Logging¶
The system log API provides a common interface to process messages issued by developers. These messages are currently printed on the terminal but the API is defined in a generic way.
This API can be deactivated through the Kconfig options, see Global Kconfig Options. This approach prevents impacting image size and execution time when the system log is not needed.
Each of the four SYS_LOG_X macros correspond to a different logging level,
The logging macros activate when their logging level or higher is set.
There are two configuration categories: configurations per module and global
configurations. When logging is enabled globally, it works for modules. However,
modules can disable logging locally. Every module can specify its own logging
level. The module must define the SYS_LOG_LEVEL macro before
including the include/logging/sys_log.h header file to do so. Unless a global
override is set, the module logging level will be honored. The global override
can only increase the logging level. It cannot be used to lower module logging
levels that were previously set higher.
You can set a local domain to differentiate messages. When no domain is set,
then the [general] domain appears before the message. Define the
SYS_LOG_DOMAIN macro before including the include/logging/sys_log.h
header file to set the domain.
When several macros are active, the printed messages can be differentiated in
two ways: by a tag printed before the message or by ANSI colors. See the
CONFIG_SYS_LOG_SHOW_TAGS and CONFIG_SYS_LOG_SHOW_COLOR
Kconfig options for more information.
Define the SYS_LOG_NO_NEWLINE macro before including the
include/logging/sys_log.h header file to prevent macros appending a new line at the
end of the logging message.
Global Kconfig Options¶
These options can be found in the following path misc/Kconfig.
CONFIG_SYS_LOG: Global switch, turns on/off all system logging.
CONFIG_SYS_LOG_DEFAULT_LEVEL: Default level, sets the logging level
used by modules that are not setting their own logging level.
CONFIG_SYS_LOG_SHOW_TAGS: Globally sets whether level tags will be
shown on log or not.
CONFIG_SYS_LOG_SHOW_COLOR: Globally sets whether ANSI colors will be
used by the system log.
CONFIG_SYS_LOG_OVERRIDE_LEVEL: It overrides module logging level when
it is not set or set lower than the override value.
Example¶
The following macro:
SYS_LOG_WRN("hi!");
Will produce:
[general] [WRN] main: Hi!
For the above example to work at least one of the following settings must be true:
- The
CONFIG_SYS_LOG_DEFAULT_LEVELis set to 2 or above and module configuration is not set. - The module configuration is set to 2 or above.
- The
CONFIG_SYS_LOG_OVERRIDE_LEVELis set to 2 or above.
APIs¶
警告
doxygengroup: Cannot find file: /home/docs/checkouts/readthedocs.org/user_builds/zephyr-doc/checkouts/master/doc/doxygen/xml/index.xml