Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Logging API

Logger API. More...

Macros

#define LOG_ERR(...)   Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__)
 Writes an ERROR level message to the log. More...
 
#define LOG_WRN(...)   Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__)
 Writes a WARNING level message to the log. More...
 
#define LOG_INF(...)   Z_LOG(LOG_LEVEL_INF, __VA_ARGS__)
 Writes an INFO level message to the log. More...
 
#define LOG_DBG(...)   Z_LOG(LOG_LEVEL_DBG, __VA_ARGS__)
 Writes a DEBUG level message to the log. More...
 
#define LOG_PRINTK(...)   Z_LOG_PRINTK(__VA_ARGS__)
 Unconditionally print raw log message. More...
 
#define LOG_INST_ERR(_log_inst, ...)    Z_LOG_INSTANCE(LOG_LEVEL_ERR, _log_inst, __VA_ARGS__)
 Writes an ERROR level message associated with the instance to the log. More...
 
#define LOG_INST_WRN(_log_inst, ...)    Z_LOG_INSTANCE(LOG_LEVEL_WRN, _log_inst, __VA_ARGS__)
 Writes a WARNING level message associated with the instance to the log. More...
 
#define LOG_INST_INF(_log_inst, ...)    Z_LOG_INSTANCE(LOG_LEVEL_INF, _log_inst, __VA_ARGS__)
 Writes an INFO level message associated with the instance to the log. More...
 
#define LOG_INST_DBG(_log_inst, ...)    Z_LOG_INSTANCE(LOG_LEVEL_DBG, _log_inst, __VA_ARGS__)
 Writes a DEBUG level message associated with the instance to the log. More...
 
#define LOG_HEXDUMP_ERR(_data, _length, _str)    Z_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, _str)
 Writes an ERROR level hexdump message to the log. More...
 
#define LOG_HEXDUMP_WRN(_data, _length, _str)    Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, _str)
 Writes a WARNING level message to the log. More...
 
#define LOG_HEXDUMP_INF(_data, _length, _str)    Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, _str)
 Writes an INFO level message to the log. More...
 
#define LOG_HEXDUMP_DBG(_data, _length, _str)    Z_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, _str)
 Writes a DEBUG level message to the log. More...
 
#define LOG_INST_HEXDUMP_ERR(_log_inst, _data, _length, _str)    Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_ERR, _log_inst, _data, _length, _str)
 Writes an ERROR hexdump message associated with the instance to the log. More...
 
#define LOG_INST_HEXDUMP_WRN(_log_inst, _data, _length, _str)    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. More...
 
#define LOG_INST_HEXDUMP_INF(_log_inst, _data, _length, _str)    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. More...
 
#define LOG_INST_HEXDUMP_DBG(_log_inst, _data, _length, _str)    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. More...
 
#define LOG_MODULE_REGISTER(...)
 Create module-specific state and register the module with Logger. More...
 
#define LOG_MODULE_DECLARE(...)
 Macro for declaring a log module (not registering it). More...
 
#define LOG_LEVEL_SET(level)
 Macro for setting log level in the file or function where instance logging API is used. More...
 

Functions

static void log_printk (const char *fmt, va_list ap)
 
static char * log_strdup (const char *str)
 

Detailed Description

Logger API.

Macro Definition Documentation

◆ LOG_DBG

#define LOG_DBG (   ...)    Z_LOG(LOG_LEVEL_DBG, __VA_ARGS__)

#include <include/logging/log.h>

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 (   ...)    Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, _str)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, _str)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, _str)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, _str)

#include <include/logging/log.h>

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 (   ...)    Z_LOG(LOG_LEVEL_INF, __VA_ARGS__)

#include <include/logging/log.h>

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,
  ... 
)     Z_LOG_INSTANCE(LOG_LEVEL_DBG, _log_inst, __VA_ARGS__)

#include <include/logging/log.h>

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,
  ... 
)     Z_LOG_INSTANCE(LOG_LEVEL_ERR, _log_inst, __VA_ARGS__)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_DBG, _log_inst, _data, _length, _str)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_ERR, _log_inst, _data, _length, _str)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_INF, _log_inst, _data, _length, _str)

#include <include/logging/log.h>

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 
)     Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_WRN, _log_inst, _data, _length, _str)

#include <include/logging/log.h>

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,
  ... 
)     Z_LOG_INSTANCE(LOG_LEVEL_INF, _log_inst, __VA_ARGS__)

#include <include/logging/log.h>

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,
  ... 
)     Z_LOG_INSTANCE(LOG_LEVEL_WRN, _log_inst, __VA_ARGS__)

#include <include/logging/log.h>

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 <include/logging/log.h>

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

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 <include/logging/log.h>

Value:
extern const struct log_source_const_data \
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 = \
_LOG_LEVEL_RESOLVE(__VA_ARGS__) ? \
&LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
NULL; \
\
static struct log_source_dynamic_data * \
__log_current_dynamic_data __unused = \
(_LOG_LEVEL_RESOLVE(__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:308
#define LOG_ITEM_DYNAMIC_DATA(_name)
Creates name of variable and section for runtime log data.
Definition: log_core.h:532
#define LOG_ITEM_CONST_DATA(_name)
Creates name of variable and section for constant log data.
Definition: log_instance.h:48
Constant data associated with the source of log messages.
Definition: log_instance.h:16
Dynamic data associated with the source of log messages.
Definition: log_instance.h:29

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 <include/logging/log.h>

Value:
Z_LOG_EVAL( \
_LOG_LEVEL_RESOLVE(__VA_ARGS__), \
(_LOG_MODULE_DATA_CREATE(GET_ARG_N(1, __VA_ARGS__), \
_LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
()/*Empty*/ \
) \
LOG_MODULE_DECLARE(__VA_ARGS__)

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

This macro normally must be used after including <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 (   ...)    Z_LOG_PRINTK(__VA_ARGS__)

#include <include/logging/log.h>

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_WRN

#define LOG_WRN (   ...)    Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__)

#include <include/logging/log.h>

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.

Function Documentation

◆ log_printk()

static void log_printk ( const char *  fmt,
va_list  ap 
)
inlinestatic

◆ log_strdup()

static char * log_strdup ( const char *  str)
inlinestatic