Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Logger API. More...

Files

file  log.h
 Header file for the logging subsystem.
file  log_core.h
 Header file for the logging core.
file  log_instance.h
 Header file for log instance registration.

Functions

static uint32_t log_const_source_id (const struct log_source_const_data *data)
 Get index of the log source based on the address of the constant data associated with the source.
static uint32_t log_dynamic_source_id (const struct log_source_dynamic_data *data)
 Get index of the log source based on the address of the dynamic data associated with the source.
static uint32_t log_source_id (const void *source)
 Get index of the log source based on the address of the associated data.
static void log_generic (uint8_t level, const char *fmt, va_list ap)
 Write a generic log message.

Standard logging

#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.

Rate-limited logging

Rate-limited variants drop repeated messages so that a frequently-hit call site cannot flood the log.

Each call site is limited independently using atomic operations for thread safety, and a summary of skipped messages is emitted when logging resumes. The plain variants use the default interval LOG_RATELIMIT_INTERVAL_MS; the _RATE variants take an explicit interval.

#define LOG_RATELIMIT_INTERVAL_MS   0
 Default interval for rate-limited log messages, in milliseconds.
#define LOG_WRN_RATELIMIT(...)
 Writes a WARNING level message to the log with rate limiting.
#define LOG_ERR_RATELIMIT(...)
 Writes an ERROR level message to the log with rate limiting.
#define LOG_INF_RATELIMIT(...)
 Writes an INFO level message to the log with rate limiting.
#define LOG_DBG_RATELIMIT(...)
 Writes a DEBUG level message to the log with rate limiting.
#define LOG_HEXDUMP_ERR_RATELIMIT(_data, _length, _str)
 Writes an ERROR level hexdump message to the log with rate limiting.
#define LOG_HEXDUMP_WRN_RATELIMIT(_data, _length, _str)
 Writes a WARNING level hexdump message to the log with rate limiting.
#define LOG_HEXDUMP_INF_RATELIMIT(_data, _length, _str)
 Writes an INFO level hexdump message to the log with rate limiting.
#define LOG_HEXDUMP_DBG_RATELIMIT(_data, _length, _str)
 Writes a DEBUG level hexdump message to the log with rate limiting.
#define LOG_ERR_RATELIMIT_RATE(_rate_ms, ...)
 Writes an ERROR level message to the log with custom rate limiting.
#define LOG_WRN_RATELIMIT_RATE(_rate_ms, ...)
 Writes a WARNING level message to the log with custom rate limiting.
#define LOG_INF_RATELIMIT_RATE(_rate_ms, ...)
 Writes an INFO level message to the log with custom rate limiting.
#define LOG_DBG_RATELIMIT_RATE(_rate_ms, ...)
 Writes a DEBUG level message to the log with custom rate limiting.
#define LOG_HEXDUMP_ERR_RATELIMIT_RATE(_rate_ms, _data, _length, _str)
 Writes an ERROR level hexdump message to the log with custom rate limiting.
#define LOG_HEXDUMP_WRN_RATELIMIT_RATE(_rate_ms, _data, _length, _str)
 Writes a WARNING level hexdump message to the log with custom rate limiting.
#define LOG_HEXDUMP_INF_RATELIMIT_RATE(_rate_ms, _data, _length, _str)
 Writes an INFO level hexdump message to the log with custom rate limiting.
#define LOG_HEXDUMP_DBG_RATELIMIT_RATE(_rate_ms, _data, _length, _str)
 Writes a DEBUG level hexdump message to the log with custom rate limiting.

Raw output

#define LOG_PRINTK(...)
 Unconditionally print raw log message.
#define LOG_RAW(...)
 Unconditionally print raw log message.

Instance logging

#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.

Hexdump logging

#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.

Instance hexdump logging

#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.

Module registration

#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.

Severity levels

#define LOG_LEVEL_NONE   0
 Severity level used to disable logging for a source.
#define LOG_LEVEL_ERR   1
 Error severity level.
#define LOG_LEVEL_WRN   2
 Warning severity level.
#define LOG_LEVEL_INF   3
 Informational severity level.
#define LOG_LEVEL_DBG   4
 Debug severity level.

Instance registration

#define LOG_OBJECT_PTR_INIT(_name, _object)
 Initialize pointer to logger instance with explicitly provided object.
#define LOG_INSTANCE_PTR(_module_name, _inst_name)
 Get pointer to a logging instance.
#define LOG_INSTANCE_PTR_INIT(_name, _module_name, _inst_name)
 Macro for initializing a pointer to the logger instance.
#define LOG_INSTANCE_PTR_DECLARE(_name)
 Declare a logger instance pointer in the module structure.
#define LOG_INSTANCE_REGISTER(_module_name, _inst_name, _level)
 Macro for registering instance for logging with independent filtering.

Detailed Description

Logger API.

Macro Definition Documentation

◆ LOG_DBG

#define LOG_DBG ( ...)

#include <log.h>

Value:
Z_LOG(LOG_LEVEL_DBG, __VA_ARGS__)
#define LOG_LEVEL_DBG
Debug severity level.
Definition log_core.h:46

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_DBG_RATELIMIT

#define LOG_DBG_RATELIMIT ( ...)

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_DBG, LOG_RATELIMIT_INTERVAL_MS, __VA_ARGS__)
#define LOG_RATELIMIT_INTERVAL_MS
Default interval for rate-limited log messages, in milliseconds.
Definition log.h:140

Writes a DEBUG level message to the log with rate limiting.

It's meant to write developer oriented information with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_DBG_RATELIMIT_RATE

#define LOG_DBG_RATELIMIT_RATE ( _rate_ms,
... )

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_DBG, _rate_ms, __VA_ARGS__)

Writes a DEBUG level message to the log with custom rate limiting.

It's meant to write developer oriented information with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

◆ LOG_ERR

#define LOG_ERR ( ...)

#include <log.h>

Value:
Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__)
#define LOG_LEVEL_ERR
Error severity level.
Definition log_core.h:40

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_ERR_RATELIMIT

#define LOG_ERR_RATELIMIT ( ...)

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_ERR, LOG_RATELIMIT_INTERVAL_MS, __VA_ARGS__)

Writes an ERROR level message to the log with rate limiting.

It's meant to report severe errors, such as those from which it's not possible to recover, but with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_ERR_RATELIMIT_RATE

#define LOG_ERR_RATELIMIT_RATE ( _rate_ms,
... )

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_ERR, _rate_ms, __VA_ARGS__)

Writes an ERROR level message to the log with custom rate limiting.

It's meant to report severe errors, such as those from which it's not possible to recover, but with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
...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 <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_DBG_RATELIMIT

#define LOG_HEXDUMP_DBG_RATELIMIT ( _data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_DBG, LOG_RATELIMIT_INTERVAL_MS, _data, _length, _str)

Writes a DEBUG level hexdump message to the log with rate limiting.

It's meant to write developer oriented information with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_HEXDUMP_DBG_RATELIMIT_RATE

#define LOG_HEXDUMP_DBG_RATELIMIT_RATE ( _rate_ms,
_data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_DBG, _rate_ms, _data, _length, _str)

Writes a DEBUG level hexdump message to the log with custom rate limiting.

It's meant to write developer oriented information with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
_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 <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_ERR_RATELIMIT

#define LOG_HEXDUMP_ERR_RATELIMIT ( _data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_ERR, LOG_RATELIMIT_INTERVAL_MS, _data, _length, _str)

Writes an ERROR level hexdump message to the log with rate limiting.

It's meant to report severe errors, such as those from which it's not possible to recover, but with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_HEXDUMP_ERR_RATELIMIT_RATE

#define LOG_HEXDUMP_ERR_RATELIMIT_RATE ( _rate_ms,
_data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_ERR, _rate_ms, _data, _length, _str)

Writes an ERROR level hexdump message to the log with custom rate limiting.

It's meant to report severe errors, such as those from which it's not possible to recover, but with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
_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 <log.h>

Value:
Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, (_str))
#define LOG_LEVEL_INF
Informational severity level.
Definition log_core.h:44

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_INF_RATELIMIT

#define LOG_HEXDUMP_INF_RATELIMIT ( _data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_INF, LOG_RATELIMIT_INTERVAL_MS, _data, _length, _str)

Writes an INFO level hexdump message to the log with rate limiting.

It's meant to write generic user oriented messages with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_HEXDUMP_INF_RATELIMIT_RATE

#define LOG_HEXDUMP_INF_RATELIMIT_RATE ( _rate_ms,
_data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_INF, _rate_ms, _data, _length, _str)

Writes an INFO level hexdump message to the log with custom rate limiting.

It's meant to write generic user oriented messages with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
_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 <log.h>

Value:
Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, (_str))
#define LOG_LEVEL_WRN
Warning severity level.
Definition log_core.h:42

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_HEXDUMP_WRN_RATELIMIT

#define LOG_HEXDUMP_WRN_RATELIMIT ( _data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_WRN, LOG_RATELIMIT_INTERVAL_MS, _data, _length, _str)

Writes a WARNING level hexdump message to the log with rate limiting.

It's meant to register messages related to unusual situations that are not necessarily errors, but with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_HEXDUMP_WRN_RATELIMIT_RATE

#define LOG_HEXDUMP_WRN_RATELIMIT_RATE ( _rate_ms,
_data,
_length,
_str )

#include <log.h>

Value:
_LOG_HEXDUMP_RATELIMIT_LVL(LOG_LEVEL_WRN, _rate_ms, _data, _length, _str)

Writes a WARNING level hexdump message to the log with custom rate limiting.

It's meant to register messages related to unusual situations that are not necessarily errors, but with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
_dataPointer to the data to be logged.
_lengthLength of data (in bytes).
_strPersistent, raw string.

◆ LOG_INF

#define LOG_INF ( ...)

#include <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_INF_RATELIMIT

#define LOG_INF_RATELIMIT ( ...)

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_INF, LOG_RATELIMIT_INTERVAL_MS, __VA_ARGS__)

Writes an INFO level message to the log with rate limiting.

It's meant to write generic user oriented messages with rate limiting to prevent log flooding. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_INF_RATELIMIT_RATE

#define LOG_INF_RATELIMIT_RATE ( _rate_ms,
... )

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_INF, _rate_ms, __VA_ARGS__)

Writes an INFO level message to the log with custom rate limiting.

It's meant to write generic user oriented messages with rate limiting to prevent log flooding. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
...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 <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 <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 <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 <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 <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 <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 <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 <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_INSTANCE_PTR

#define LOG_INSTANCE_PTR ( _module_name,
_inst_name )

#include <log_instance.h>

Value:
Z_LOG_OBJECT_PTR(Z_LOG_INSTANCE_FULL_NAME(_module_name, _inst_name))

Get pointer to a logging instance.

Instance is identified by _module_name and _inst_name.

Parameters
_module_nameModule name.
_inst_nameInstance name.
Returns
Pointer to a logging instance.

◆ LOG_INSTANCE_PTR_DECLARE

#define LOG_INSTANCE_PTR_DECLARE ( _name)

#include <log_instance.h>

Value:
COND_CODE_1(CONFIG_LOG, (Z_LOG_INSTANCE_STRUCT * _name), \
(int _name[TOOLCHAIN_HAS_ZLA ? 0 : 1]))
#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:209
#define TOOLCHAIN_HAS_ZLA
Indicate if toolchain supports Zero Length Arrays.
Definition toolchain.h:138

Declare a logger instance pointer in the module structure.

If logging is disabled then element in the structure is still declared to avoid compilation issues. If compiler supports zero length arrays then it is utilized to not use any space, else a byte array is created.

Parameters
_nameName of a structure element that will have a pointer to logging instance object.

◆ LOG_INSTANCE_PTR_INIT

#define LOG_INSTANCE_PTR_INIT ( _name,
_module_name,
_inst_name )

#include <log_instance.h>

Value:
LOG_OBJECT_PTR_INIT(_name, LOG_INSTANCE_PTR(_module_name, _inst_name))
#define LOG_OBJECT_PTR_INIT(_name, _object)
Initialize pointer to logger instance with explicitly provided object.
Definition log_instance.h:88
#define LOG_INSTANCE_PTR(_module_name, _inst_name)
Get pointer to a logging instance.
Definition log_instance.h:121

Macro for initializing a pointer to the logger instance.

_module_name and _inst_name are concatenated to form a name of the object.

Macro is intended to be used in user structure initializer to initialize a field in the structure that holds pointer to the logging instance. Structure field should be declared using LOG_INSTANCE_PTR_DECLARE.

Parameters
_nameName of a structure element that have a pointer to logging instance object.
_module_nameModule name.
_inst_nameInstance name.

◆ LOG_INSTANCE_REGISTER

#define LOG_INSTANCE_REGISTER ( _module_name,
_inst_name,
_level )

#include <log_instance.h>

Value:
IF_ENABLED(CONFIG_LOG, (Z_LOG_INSTANCE_REGISTER(_module_name, _inst_name, _level)))
#define IF_ENABLED(_flag, _code)
Insert code if _flag is defined and equals 1.
Definition util_macro.h:278

Macro for registering instance for logging with independent filtering.

Module instance provides filtering of logs on instance level instead of module level. Instance create using this macro can later on be used with LOG_INSTANCE_PTR_INIT or referenced by LOG_INSTANCE_PTR.

Parameters
_module_nameModule name.
_inst_nameInstance name.
_levelInitial static filtering.

◆ LOG_LEVEL_DBG

#define LOG_LEVEL_DBG   4

#include <log_core.h>

Debug severity level.

◆ LOG_LEVEL_ERR

#define LOG_LEVEL_ERR   1

#include <log_core.h>

Error severity level.

◆ LOG_LEVEL_INF

#define LOG_LEVEL_INF   3

#include <log_core.h>

Informational severity level.

◆ LOG_LEVEL_NONE

#define LOG_LEVEL_NONE   0

#include <log_core.h>

Severity level used to disable logging for a source.

◆ LOG_LEVEL_SET

#define LOG_LEVEL_SET ( level)

#include <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_LEVEL_WRN

#define LOG_LEVEL_WRN   2

#include <log_core.h>

Warning severity level.

◆ LOG_MODULE_DECLARE

#define LOG_MODULE_DECLARE ( ...)

#include <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__)); \
\
Z_LOG_MODULE_PARTITION(K_APP_DMEM) \
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; \
\
Z_LOG_MODULE_PARTITION(K_APP_DMEM) \
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; \
\
Z_LOG_MODULE_PARTITION(K_APP_BMEM) \
static const uint32_t __log_level __unused = _LOG_LEVEL_RESOLVE(__VA_ARGS__)
#define K_APP_BMEM(id)
Place data in a partition's bss section.
Definition app_memdomain.h:61
#define K_APP_DMEM(id)
Place data in a partition's data section.
Definition app_memdomain.h:51
#define GET_ARG_N(N,...)
Get nth argument from argument list.
Definition util_macro.h:422
#define NULL
Definition iar_missing_defs.h:20

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 <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__)

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_OBJECT_PTR_INIT

#define LOG_OBJECT_PTR_INIT ( _name,
_object )

#include <log_instance.h>

Value:
IF_ENABLED(CONFIG_LOG, (._name = _object,))

Initialize pointer to logger instance with explicitly provided object.

Macro can be used to initialized a pointer with object that is not unique to the given instance, thus not created with LOG_INSTANCE_REGISTER.

Parameters
_nameName of the structure element for holding logging object.
_objectPointer to a logging instance object.

◆ LOG_PRINTK

#define LOG_PRINTK ( ...)

#include <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_RATELIMIT_INTERVAL_MS

#define LOG_RATELIMIT_INTERVAL_MS   0

#include <log.h>

Default interval for rate-limited log messages, in milliseconds.

Period used by the rate-limited logging macros that do not take an explicit rate (for example LOG_ERR_RATELIMIT). It evaluates to

CONFIG_LOG_RATELIMIT_INTERVAL_MS 

when

CONFIG_LOG_RATELIMIT 

is enabled, and to 0 (no rate limiting) otherwise.

◆ LOG_RAW

#define LOG_RAW ( ...)

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

Value:
do { \
static atomic_t __warned; \
if (unlikely(atomic_cas(&__warned, 0, 1))) { \
Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__); \
} \
} while (0)
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.

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.

◆ LOG_WRN_RATELIMIT

#define LOG_WRN_RATELIMIT ( ...)

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_WRN, LOG_RATELIMIT_INTERVAL_MS, __VA_ARGS__)

Writes a WARNING level message to the log with rate limiting.

It's meant for situations that warrant investigation but could clutter the logs if output too frequently. The message will be logged at most once per default interval (see CONFIG_LOG_RATELIMIT_INTERVAL_MS).

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

◆ LOG_WRN_RATELIMIT_RATE

#define LOG_WRN_RATELIMIT_RATE ( _rate_ms,
... )

#include <log.h>

Value:
_LOG_RATELIMIT_LVL(LOG_LEVEL_WRN, _rate_ms, __VA_ARGS__)

Writes a WARNING level message to the log with custom rate limiting.

It's meant for situations that warrant investigation but could clutter the logs if output too frequently. The message will be logged at most once per specified interval.

Parameters
_rate_msMinimum interval in milliseconds between log messages.
...A string optionally containing printk valid conversion specifier, followed by as many values as specifiers.

Function Documentation

◆ log_const_source_id()

uint32_t log_const_source_id ( const struct log_source_const_data * data)
inlinestatic

#include <log_core.h>

Get index of the log source based on the address of the constant data associated with the source.

Parameters
dataAddress of the constant data.
Returns
Source ID.

◆ log_dynamic_source_id()

uint32_t log_dynamic_source_id ( const struct log_source_dynamic_data * data)
inlinestatic

#include <log_core.h>

Get index of the log source based on the address of the dynamic data associated with the source.

Parameters
dataAddress of the dynamic data.
Returns
Source ID.

◆ log_generic()

void log_generic ( uint8_t level,
const char * fmt,
va_list ap )
inlinestatic

#include <log_core.h>

Write a generic log message.

Note
This function is intended to be used when porting other log systems.
Parameters
levelLog level.
fmtString to format.
apPointer to arguments list.

◆ log_source_id()

uint32_t log_source_id ( const void * source)
inlinestatic

#include <log_core.h>

Get index of the log source based on the address of the associated data.

Parameters
sourceAddress of the data structure (dynamic if runtime filtering is enabled and static otherwise).
Returns
Source ID.