Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Logger API . More...

Macros

#define LOG_ERR(...)
 Writes an ERROR level message to the log.
 
#define LOG_WRN(...)
 Writes a WARNING level message to the log.
 
#define LOG_INF(...)
 Writes an INFO level message to the log.
 
#define LOG_DBG(...)
 Writes a DEBUG level message to the log.
 
#define LOG_WRN_ONCE(...)
 Writes a WARNING level message to the log on the first execution only.
 
#define LOG_PRINTK(...)
 Unconditionally print raw log message.
 
#define LOG_RAW(...)
 Unconditionally print raw log message.
 
#define LOG_INST_ERR(_log_inst, ...)
 Writes an ERROR level message associated with the instance to the log.
 
#define LOG_INST_WRN(_log_inst, ...)
 Writes a WARNING level message associated with the instance to the log.
 
#define LOG_INST_INF(_log_inst, ...)
 Writes an INFO level message associated with the instance to the log.
 
#define LOG_INST_DBG(_log_inst, ...)
 Writes a DEBUG level message associated with the instance to the log.
 
#define LOG_HEXDUMP_ERR(_data, _length, _str)
 Writes an ERROR level hexdump message to the log.
 
#define LOG_HEXDUMP_WRN(_data, _length, _str)
 Writes a WARNING level message to the log.
 
#define LOG_HEXDUMP_INF(_data, _length, _str)
 Writes an INFO level message to the log.
 
#define LOG_HEXDUMP_DBG(_data, _length, _str)
 Writes a DEBUG level message to the log.
 
#define LOG_INST_HEXDUMP_ERR(_log_inst, _data, _length, _str)
 Writes an ERROR hexdump message associated with the instance to the log.
 
#define LOG_INST_HEXDUMP_WRN(_log_inst, _data, _length, _str)
 Writes a WARNING level hexdump message associated with the instance to the log.
 
#define LOG_INST_HEXDUMP_INF(_log_inst, _data, _length, _str)
 Writes an INFO level hexdump message associated with the instance to the log.
 
#define LOG_INST_HEXDUMP_DBG(_log_inst, _data, _length, _str)
 Writes a DEBUG level hexdump message associated with the instance to the log.
 
#define LOG_MODULE_REGISTER(...)
 Create module-specific state and register the module with Logger.
 
#define LOG_MODULE_DECLARE(...)
 Macro for declaring a log module (not registering it).
 
#define LOG_LEVEL_SET(level)
 Macro for setting log level in the file or function where instance logging API is used.
 

Detailed Description

Logger API .

Macro Definition Documentation

◆ LOG_DBG

#define LOG_DBG ( ...)

#include <zephyr/logging/log.h>

Value:
Z_LOG(LOG_LEVEL_DBG, __VA_ARGS__)
#define LOG_LEVEL_DBG
Definition log_core.h:23

Writes a DEBUG level message to the log.

It's meant to write developer oriented information.

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_ERR

#define LOG_ERR ( ...)

#include <zephyr/logging/log.h>

Value:
Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__)
#define LOG_LEVEL_ERR
Definition log_core.h:20

Writes an ERROR level message to the log.

It's meant to report severe errors, such as those from which it's not possible to recover.

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_HEXDUMP_DBG

#define LOG_HEXDUMP_DBG ( _data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, (_str))

Writes a DEBUG level message to the log.

It's meant to write developer oriented information.

Parameters
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_HEXDUMP_ERR

#define LOG_HEXDUMP_ERR ( _data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, (_str))

Writes an ERROR level hexdump message to the log.

It's meant to report severe errors, such as those from which it's not possible to recover.

Parameters
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_HEXDUMP_INF

#define LOG_HEXDUMP_INF ( _data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, (_str))
#define LOG_LEVEL_INF
Definition log_core.h:22

Writes an INFO level message to the log.

It's meant to write generic user oriented messages.

Parameters
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_HEXDUMP_WRN

#define LOG_HEXDUMP_WRN ( _data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, (_str))
#define LOG_LEVEL_WRN
Definition log_core.h:21

Writes a WARNING level message to the log.

It's meant to register messages related to unusual situations that are not necessarily errors.

Parameters
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_INF

#define LOG_INF ( ...)

#include <zephyr/logging/log.h>

Value:
Z_LOG(LOG_LEVEL_INF, __VA_ARGS__)

Writes an INFO level message to the log.

It's meant to write generic user oriented messages.

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_INST_DBG

#define LOG_INST_DBG ( _log_inst,
... )

#include <zephyr/logging/log.h>

Value:
Z_LOG_INSTANCE(LOG_LEVEL_DBG, _log_inst, __VA_ARGS__)

Writes a DEBUG level message associated with the instance to the log.

Message is associated with specific instance of the module which has independent filtering settings (if runtime filtering is enabled) and message prefix (<module_name>.<instance_name>). It's meant to write developer oriented information.

Parameters
_log_instPointer to the log structure associated with the instance.
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_INST_ERR

#define LOG_INST_ERR ( _log_inst,
... )

#include <zephyr/logging/log.h>

Value:
Z_LOG_INSTANCE(LOG_LEVEL_ERR, _log_inst, __VA_ARGS__)

Writes an ERROR level message associated with the instance to the log.

Message is associated with specific instance of the module which has independent filtering settings (if runtime filtering is enabled) and message prefix (<module_name>.<instance_name>). It's meant to report severe errors, such as those from which it's not possible to recover.

Parameters
_log_instPointer to the log structure associated with the instance.
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_INST_HEXDUMP_DBG

#define LOG_INST_HEXDUMP_DBG ( _log_inst,
_data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_DBG, _log_inst, _data, _length, _str)

Writes a DEBUG level hexdump message associated with the instance to the log.

It's meant to write developer oriented information.

Parameters
_log_instPointer to the log structure associated with the instance.
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_INST_HEXDUMP_ERR

#define LOG_INST_HEXDUMP_ERR ( _log_inst,
_data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_ERR, _log_inst, _data, _length, _str)

Writes an ERROR hexdump message associated with the instance to the log.

Message is associated with specific instance of the module which has independent filtering settings (if runtime filtering is enabled) and message prefix (<module_name>.<instance_name>). It's meant to report severe errors, such as those from which it's not possible to recover.

Parameters
_log_instPointer to the log structure associated with the instance.
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_INST_HEXDUMP_INF

#define LOG_INST_HEXDUMP_INF ( _log_inst,
_data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_INF, _log_inst, _data, _length, _str)

Writes an INFO level hexdump message associated with the instance to the log.

It's meant to write generic user oriented messages.

Parameters
_log_instPointer to the log structure associated with the instance.
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_INST_HEXDUMP_WRN

#define LOG_INST_HEXDUMP_WRN ( _log_inst,
_data,
_length,
_str )

#include <zephyr/logging/log.h>

Value:
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_WRN, _log_inst, _data, _length, _str)

Writes a WARNING level hexdump message associated with the instance to the log.

It's meant to register messages related to unusual situations that are not necessarily errors.

Parameters
_log_instPointer to the log structure associated with the instance.
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_INST_INF

#define LOG_INST_INF ( _log_inst,
... )

#include <zephyr/logging/log.h>

Value:
Z_LOG_INSTANCE(LOG_LEVEL_INF, _log_inst, __VA_ARGS__)

Writes an INFO level message associated with the instance to the log.

Message is associated with specific instance of the module which has independent filtering settings (if runtime filtering is enabled) and message prefix (<module_name>.<instance_name>). It's meant to write generic user oriented messages.

Parameters
_log_instPointer to the log structure associated with the instance.
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_INST_WRN

#define LOG_INST_WRN ( _log_inst,
... )

#include <zephyr/logging/log.h>

Value:
Z_LOG_INSTANCE(LOG_LEVEL_WRN, _log_inst, __VA_ARGS__)

Writes a WARNING level message associated with the instance to the log.

Message is associated with specific instance of the module which has independent filtering settings (if runtime filtering is enabled) and message prefix (<module_name>.<instance_name>). It's meant to register messages related to unusual situations that are not necessarily errors.

Parameters
_log_instPointer to the log structure associated with the instance.
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_LEVEL_SET

#define LOG_LEVEL_SET ( level)

#include <zephyr/logging/log.h>

Value:
static const uint32_t __log_level __unused = \
Z_LOG_RESOLVED_LEVEL(level, 0)
__UINT32_TYPE__ uint32_t
Definition stdint.h:90

Macro for setting log level in the file or function where instance logging API is used.

Parameters
levelLevel used in file or in function.

◆ LOG_MODULE_DECLARE

#define LOG_MODULE_DECLARE ( ...)

#include <zephyr/logging/log.h>

Value:
extern const struct log_source_const_data \
Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)); \
extern struct log_source_dynamic_data \
LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)); \
\
static const struct log_source_const_data * \
__log_current_const_data __unused = \
Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) ? \
&Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
NULL; \
\
static struct log_source_dynamic_data * \
__log_current_dynamic_data __unused = \
(Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) && \
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ? \
&LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
NULL; \
\
static const uint32_t __log_level __unused = \
_LOG_LEVEL_RESOLVE(__VA_ARGS__)
#define GET_ARG_N(N,...)
Get nth argument from argument list.
Definition util_macro.h:371
#define LOG_ITEM_DYNAMIC_DATA(_name)
Creates name of variable and section for runtime log data.
Definition log_core.h:481
Constant data associated with the source of log messages.
Definition log_instance.h:17
Dynamic data associated with the source of log messages.
Definition log_instance.h:30

Macro for declaring a log module (not registering it).

Modules which are split up over multiple files must have exactly one file use LOG_MODULE_REGISTER() to create module-specific state and register the module with the logger core.

The other files in the module should use this macro instead to declare that same state. (Otherwise, LOG_INF() etc. will not be able to refer to module-specific state variables.)

Macro accepts one or two parameters:

  • module name
  • optional log level. If not provided then default log level is used in the file.

Example usage:

Note
The module's state is declared only if LOG_LEVEL for the current source file is non-zero or it is not defined and CONFIG_LOG_DEFAULT_LEVEL is non-zero. In other cases, this macro has no effect.
See also
LOG_MODULE_REGISTER

◆ LOG_MODULE_REGISTER

#define LOG_MODULE_REGISTER ( ...)

#include <zephyr/logging/log.h>

Value:
Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__), \
(_LOG_MODULE_DATA_CREATE(GET_ARG_N(1, __VA_ARGS__), \
_LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
() \
) \
LOG_MODULE_DECLARE(__VA_ARGS__)
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195

Create module-specific state and register the module with Logger.

This macro normally must be used after including <zephyr/logging/log.h> to complete the initialization of the module.

Module registration can be skipped in two cases:

  • The module consists of more than one file, and another file invokes this macro. (LOG_MODULE_DECLARE() should be used instead in all of the module's other files.)
  • Instance logging is used and there is no need to create module entry. In that case LOG_LEVEL_SET() should be used to set log level used within the file.

Macro accepts one or two parameters:

  • module name
  • optional log level. If not provided then default log level is used in the file.

Example usage:

Note
The module's state is defined, and the module is registered, only if LOG_LEVEL for the current source file is non-zero or it is not defined and CONFIG_LOG_DEFAULT_LEVEL is non-zero. In other cases, this macro has no effect.
See also
LOG_MODULE_DECLARE

◆ LOG_PRINTK

#define LOG_PRINTK ( ...)

#include <zephyr/logging/log.h>

Value:
Z_LOG_PRINTK(0, __VA_ARGS__)

Unconditionally print raw log message.

The result is same as if printk was used but it goes through logging infrastructure thus utilizes logging mode, e.g. deferred mode.

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_RAW

#define LOG_RAW ( ...)

#include <zephyr/logging/log.h>

Value:
Z_LOG_PRINTK(1, __VA_ARGS__)

Unconditionally print raw log message.

Provided string is printed as is without appending any characters (e.g., color or newline).

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_WRN

#define LOG_WRN ( ...)

#include <zephyr/logging/log.h>

Value:
Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__)

Writes a WARNING level message to the log.

It's meant to register messages related to unusual situations that are not necessarily errors.

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_WRN_ONCE

#define LOG_WRN_ONCE ( ...)

#include <zephyr/logging/log.h>

Value:
do { \
static uint8_t __warned; \
if (unlikely(__warned == 0)) { \
Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__); \
__warned = 1; \
} \
} while (0)
__UINT8_TYPE__ uint8_t
Definition stdint.h:88

Writes a WARNING level message to the log on the first execution only.

It's meant for situations that warrant investigation but could clutter the logs if output on every execution.

Parameters
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.