Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
log_core.h File Reference
#include <logging/log_msg.h>
#include <logging/log_core2.h>
#include <logging/log_instance.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#include <syscall.h>
#include <sys/util.h>
#include <syscalls/log_core.h>

Go to the source code of this file.

Macros

#define LOG_LEVEL_NONE   0U
 
#define LOG_LEVEL_ERR   1U
 
#define LOG_LEVEL_WRN   2U
 
#define LOG_LEVEL_INF   3U
 
#define LOG_LEVEL_DBG   4U
 
#define CONFIG_LOG_DEFAULT_LEVEL   0U
 
#define CONFIG_LOG_MAX_LEVEL   0U
 
#define CONFIG_LOG_DOMAIN_ID   0U
 
#define LOG_FUNCTION_PREFIX_MASK
 
#define LOG_CONST_ID_GET(_addr)    COND_CODE_1(CONFIG_LOG, ((__log_level ? log_const_source_id(_addr) : 0)), (0))
 Macro for getting ID of the element of the section. More...
 
#define LOG_CURRENT_MODULE_ID()
 Macro for getting ID of current module. More...
 
#define LOG_CURRENT_DYNAMIC_DATA_ADDR()
 Macro for getting address of dynamic structure of current module. More...
 
#define LOG_DYNAMIC_ID_GET(_addr)    COND_CODE_1(CONFIG_LOG, ((__log_level ? log_dynamic_source_id(_addr) : 0)), (0))
 Macro for getting ID of the element of the section. More...
 
#define LOG_LEVEL_BITS   3U
 Number of bits used to encode log level. More...
 
#define LOG_FILTER_SLOT_SIZE   LOG_LEVEL_BITS
 Filter slot size. More...
 
#define LOG_FILTERS_NUM_OF_SLOTS   (32 / LOG_FILTER_SLOT_SIZE)
 Number of slots in one word. More...
 
#define LOG_FILTER_SLOT_MASK   (BIT(LOG_FILTER_SLOT_SIZE) - 1U)
 Slot mask. More...
 
#define LOG_FILTER_SLOT_SHIFT(_id)   (LOG_FILTER_SLOT_SIZE * (_id))
 Bit offset of a slot. More...
 
#define LOG_FILTER_SLOT_GET(_filters, _id)    ((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK)
 
#define LOG_FILTER_SLOT_SET(_filters, _id, _filter)
 
#define LOG_FILTER_AGGR_SLOT_IDX   0
 
#define LOG_FILTER_AGGR_SLOT_GET(_filters)    LOG_FILTER_SLOT_GET(_filters, LOG_FILTER_AGGR_SLOT_IDX)
 
#define LOG_FILTER_FIRST_BACKEND_SLOT_IDX   1
 
#define LOG_LEVEL_INTERNAL_RAW_STRING   LOG_LEVEL_NONE
 Log level value used to indicate log entry that should not be formatted (raw string). More...
 
#define LOG_ITEM_DYNAMIC_DATA(_name)   UTIL_CAT(log_dynamic_, _name)
 Creates name of variable and section for runtime log data. More...
 
#define LOG_INSTANCE_DYNAMIC_DATA(_module_name, _inst)    LOG_ITEM_DYNAMIC_DATA(LOG_INSTANCE_FULL_NAME(_module_name, _inst))
 

Enumerations

enum  log_strdup_action { LOG_STRDUP_SKIP , LOG_STRDUP_EXEC , LOG_STRDUP_CHECK_EXEC }
 Enum with possible actions for strdup operation. More...
 

Functions

static const char * log_name_get (uint32_t source_id)
 Get name of the log source. More...
 
static uint8_t log_compiled_level_get (uint32_t source_id)
 Get compiled level of the log source. More...
 
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. More...
 
static uint32_t log_sources_count (void)
 Get number of registered sources. More...
 
static uint32_tlog_dynamic_filters_get (uint32_t source_id)
 Get pointer to the filter set of the log source. More...
 
static uint32_t log_dynamic_source_id (struct log_source_dynamic_data *data)
 Get index of the log source based on the address of the dynamic data associated with the source. More...
 
void log_0 (const char *str, struct log_msg_ids src_level)
 Standard log with no arguments. More...
 
void log_1 (const char *str, log_arg_t arg1, struct log_msg_ids src_level)
 Standard log with one argument. More...
 
void log_2 (const char *str, log_arg_t arg1, log_arg_t arg2, struct log_msg_ids src_level)
 Standard log with two arguments. More...
 
void log_3 (const char *str, log_arg_t arg1, log_arg_t arg2, log_arg_t arg3, struct log_msg_ids src_level)
 Standard log with three arguments. More...
 
void log_n (const char *str, log_arg_t *args, uint32_t narg, struct log_msg_ids src_level)
 Standard log with arguments list. More...
 
void log_hexdump (const char *str, const void *data, uint32_t length, struct log_msg_ids src_level)
 Hexdump log. More...
 
void log_string_sync (struct log_msg_ids src_level, const char *fmt,...)
 Process log message synchronously. More...
 
void log_hexdump_sync (struct log_msg_ids src_level, const char *metadata, const void *data, uint32_t len)
 Process log hexdump message synchronously. More...
 
void log_generic (struct log_msg_ids src_level, const char *fmt, va_list ap, enum log_strdup_action strdup_action)
 Writes a generic log message to the log. More...
 
static void log2_generic (uint8_t level, const char *fmt, va_list ap)
 Writes a generic log message to the logging v2. More...
 
uint32_t log_count_args (const char *fmt)
 Returns number of arguments visible from format string. More...
 
void log_generic_from_user (struct log_msg_ids src_level, const char *fmt, va_list ap)
 Writes a generic log message to the log from user mode. More...
 
bool log_is_strdup (const void *buf)
 Check if address belongs to the memory pool used for transient. More...
 
void log_free (void *buf)
 Free allocated buffer. More...
 
uint32_t log_get_strdup_pool_current_utilization (void)
 Get current number of allocated buffers for string duplicates. More...
 
uint32_t log_get_strdup_pool_utilization (void)
 Get maximal number of simultaneously allocated buffers for string duplicates. More...
 
uint32_t log_get_strdup_longest_string (void)
 Get length of the longest string duplicated. More...
 
void log_from_user (struct log_msg_ids src_level, const char *fmt,...)
 Log a message from user mode context. More...
 
void log_hexdump_from_user (struct log_msg_ids src_level, const char *metadata, const void *data, uint32_t len)
 Log binary data (displayed as hexdump) from user mode context. More...
 

Macro Definition Documentation

◆ CONFIG_LOG_DEFAULT_LEVEL

#define CONFIG_LOG_DEFAULT_LEVEL   0U

◆ CONFIG_LOG_DOMAIN_ID

#define CONFIG_LOG_DOMAIN_ID   0U

◆ CONFIG_LOG_MAX_LEVEL

#define CONFIG_LOG_MAX_LEVEL   0U

◆ LOG_CONST_ID_GET

#define LOG_CONST_ID_GET (   _addr)     COND_CODE_1(CONFIG_LOG, ((__log_level ? log_const_source_id(_addr) : 0)), (0))

Macro for getting ID of the element of the section.

Parameters
_addrAddress of the element.

◆ LOG_CURRENT_DYNAMIC_DATA_ADDR

#define LOG_CURRENT_DYNAMIC_DATA_ADDR ( )
Value:
(__log_level ? \
__log_current_dynamic_data : (struct log_source_dynamic_data *)0U)
Dynamic data associated with the source of log messages.
Definition: log_instance.h:29

Macro for getting address of dynamic structure of current module.

◆ LOG_CURRENT_MODULE_ID

#define LOG_CURRENT_MODULE_ID ( )
Value:
(__log_level != 0 ? \
log_const_source_id(__log_current_const_data) : 0U)

Macro for getting ID of current module.

◆ LOG_DYNAMIC_ID_GET

#define LOG_DYNAMIC_ID_GET (   _addr)     COND_CODE_1(CONFIG_LOG, ((__log_level ? log_dynamic_source_id(_addr) : 0)), (0))

Macro for getting ID of the element of the section.

Parameters
_addrAddress of the element.

◆ LOG_FILTER_AGGR_SLOT_GET

#define LOG_FILTER_AGGR_SLOT_GET (   _filters)     LOG_FILTER_SLOT_GET(_filters, LOG_FILTER_AGGR_SLOT_IDX)

◆ LOG_FILTER_AGGR_SLOT_IDX

#define LOG_FILTER_AGGR_SLOT_IDX   0

◆ LOG_FILTER_FIRST_BACKEND_SLOT_IDX

#define LOG_FILTER_FIRST_BACKEND_SLOT_IDX   1

◆ LOG_FILTER_SLOT_GET

#define LOG_FILTER_SLOT_GET (   _filters,
  _id 
)     ((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK)

◆ LOG_FILTER_SLOT_MASK

#define LOG_FILTER_SLOT_MASK   (BIT(LOG_FILTER_SLOT_SIZE) - 1U)

Slot mask.

◆ LOG_FILTER_SLOT_SET

#define LOG_FILTER_SLOT_SET (   _filters,
  _id,
  _filter 
)
Value:
do { \
*(_filters) &= ~(LOG_FILTER_SLOT_MASK << \
*(_filters) |= ((_filter) & LOG_FILTER_SLOT_MASK) << \
} while (false)
#define LOG_FILTER_SLOT_SHIFT(_id)
Bit offset of a slot.
Definition: log_core.h:428
#define LOG_FILTER_SLOT_MASK
Slot mask.
Definition: log_core.h:422

◆ LOG_FILTER_SLOT_SHIFT

#define LOG_FILTER_SLOT_SHIFT (   _id)    (LOG_FILTER_SLOT_SIZE * (_id))

Bit offset of a slot.

Parameters
_idSlot ID.

◆ LOG_FILTER_SLOT_SIZE

#define LOG_FILTER_SLOT_SIZE   LOG_LEVEL_BITS

Filter slot size.

◆ LOG_FILTERS_NUM_OF_SLOTS

#define LOG_FILTERS_NUM_OF_SLOTS   (32 / LOG_FILTER_SLOT_SIZE)

Number of slots in one word.

◆ LOG_FUNCTION_PREFIX_MASK

#define LOG_FUNCTION_PREFIX_MASK
Value:
(((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_ERR) << \
LOG_LEVEL_ERR) | \
((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_WRN) << \
LOG_LEVEL_WRN) | \
((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_INF) << \
LOG_LEVEL_INF) | \
((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_DBG) << LOG_LEVEL_DBG))
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition: util_macro.h:101
#define LOG_LEVEL_DBG
Definition: log_core.h:22
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60

◆ LOG_INSTANCE_DYNAMIC_DATA

#define LOG_INSTANCE_DYNAMIC_DATA (   _module_name,
  _inst 
)     LOG_ITEM_DYNAMIC_DATA(LOG_INSTANCE_FULL_NAME(_module_name, _inst))

◆ LOG_ITEM_DYNAMIC_DATA

#define LOG_ITEM_DYNAMIC_DATA (   _name)    UTIL_CAT(log_dynamic_, _name)

Creates name of variable and section for runtime log data.

Parameters
_nameName.

◆ LOG_LEVEL_BITS

#define LOG_LEVEL_BITS   3U

Number of bits used to encode log level.

◆ LOG_LEVEL_DBG

#define LOG_LEVEL_DBG   4U

◆ LOG_LEVEL_ERR

#define LOG_LEVEL_ERR   1U

◆ LOG_LEVEL_INF

#define LOG_LEVEL_INF   3U

◆ LOG_LEVEL_INTERNAL_RAW_STRING

#define LOG_LEVEL_INTERNAL_RAW_STRING   LOG_LEVEL_NONE

Log level value used to indicate log entry that should not be formatted (raw string).

◆ LOG_LEVEL_NONE

#define LOG_LEVEL_NONE   0U

◆ LOG_LEVEL_WRN

#define LOG_LEVEL_WRN   2U

Enumeration Type Documentation

◆ log_strdup_action

Enum with possible actions for strdup operation.

Enumerator
LOG_STRDUP_SKIP 

None RAM string duplication.

LOG_STRDUP_EXEC 

Always duplicate RAM strings.

LOG_STRDUP_CHECK_EXEC 

Duplicate RAM strings, if not dupl. before.

Function Documentation

◆ log2_generic()

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

Writes a generic log message to the logging v2.

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

◆ log_0()

void log_0 ( const char *  str,
struct log_msg_ids  src_level 
)

Standard log with no arguments.

Parameters
strString.
src_levelLog identification.

◆ log_1()

void log_1 ( const char *  str,
log_arg_t  arg1,
struct log_msg_ids  src_level 
)

Standard log with one argument.

Parameters
strString.
arg1First argument.
src_levelLog identification.

◆ log_2()

void log_2 ( const char *  str,
log_arg_t  arg1,
log_arg_t  arg2,
struct log_msg_ids  src_level 
)

Standard log with two arguments.

Parameters
strString.
arg1First argument.
arg2Second argument.
src_levelLog identification.

◆ log_3()

void log_3 ( const char *  str,
log_arg_t  arg1,
log_arg_t  arg2,
log_arg_t  arg3,
struct log_msg_ids  src_level 
)

Standard log with three arguments.

Parameters
strString.
arg1First argument.
arg2Second argument.
arg3Third argument.
src_levelLog identification.

◆ log_compiled_level_get()

static uint8_t log_compiled_level_get ( uint32_t  source_id)
inlinestatic

Get compiled level of the log source.

Parameters
source_idSource ID.
Returns
Level.

◆ log_const_source_id()

static uint32_t log_const_source_id ( const struct log_source_const_data data)
inlinestatic

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_count_args()

uint32_t log_count_args ( const char *  fmt)

Returns number of arguments visible from format string.

Note
This function is intended to be used when porting other log systems.
Parameters
fmtFormat string.
Returns
Number of arguments.

◆ log_dynamic_filters_get()

static uint32_t * log_dynamic_filters_get ( uint32_t  source_id)
inlinestatic

Get pointer to the filter set of the log source.

Parameters
source_idSource ID.
Returns
Pointer to the filter set.

◆ log_dynamic_source_id()

static uint32_t log_dynamic_source_id ( struct log_source_dynamic_data data)
inlinestatic

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_free()

void log_free ( void buf)

Free allocated buffer.

Parameters
bufBuffer.

◆ log_from_user()

void log_from_user ( struct log_msg_ids  src_level,
const char *  fmt,
  ... 
)

Log a message from user mode context.

Note
This function is intended to be used internally by the logging subsystem.
Parameters
src_levelLog identification.
fmtString to format.
...Variable list of arguments.

◆ log_generic()

void log_generic ( struct log_msg_ids  src_level,
const char *  fmt,
va_list  ap,
enum log_strdup_action  strdup_action 
)

Writes a generic log message to the log.

Note
This function is intended to be used when porting other log systems.
Parameters
src_levelLog identification.
fmtString to format.
apPoiner to arguments list.
strdup_actionManages strdup activity.

◆ log_generic_from_user()

void log_generic_from_user ( struct log_msg_ids  src_level,
const char *  fmt,
va_list  ap 
)

Writes a generic log message to the log from user mode.

Note
This function is intended to be used internally by the logging subsystem.

◆ log_get_strdup_longest_string()

uint32_t log_get_strdup_longest_string ( void  )

Get length of the longest string duplicated.

Value can be used to determine buffer size in the string duplicates pool.

◆ log_get_strdup_pool_current_utilization()

uint32_t log_get_strdup_pool_current_utilization ( void  )

Get current number of allocated buffers for string duplicates.

◆ log_get_strdup_pool_utilization()

uint32_t log_get_strdup_pool_utilization ( void  )

Get maximal number of simultaneously allocated buffers for string duplicates.

Value can be used to determine pool size.

◆ log_hexdump()

void log_hexdump ( const char *  str,
const void data,
uint32_t  length,
struct log_msg_ids  src_level 
)

Hexdump log.

Parameters
strString.
dataData.
lengthData length.
src_levelLog identification.

◆ log_hexdump_from_user()

void log_hexdump_from_user ( struct log_msg_ids  src_level,
const char *  metadata,
const void data,
uint32_t  len 
)

Log binary data (displayed as hexdump) from user mode context.

Note
This function is intended to be used internally by the logging subsystem.
Parameters
src_levelLog identification.
metadataRaw string associated with the data.
dataData.
lenData length.

◆ log_hexdump_sync()

void log_hexdump_sync ( struct log_msg_ids  src_level,
const char *  metadata,
const void data,
uint32_t  len 
)

Process log hexdump message synchronously.

Parameters
src_levelLog message details.
metadataRaw string associated with the data.
dataData.
lenData length.

◆ log_is_strdup()

bool log_is_strdup ( const void buf)

Check if address belongs to the memory pool used for transient.

Parameters
bufBuffer.
Returns
True if address within the pool, false otherwise.

◆ log_n()

void log_n ( const char *  str,
log_arg_t args,
uint32_t  narg,
struct log_msg_ids  src_level 
)

Standard log with arguments list.

Parameters
strString.
argsArray with arguments.
nargNumber of arguments in the array.
src_levelLog identification.

◆ log_name_get()

static const char * log_name_get ( uint32_t  source_id)
inlinestatic

Get name of the log source.

Parameters
source_idSource ID.
Returns
Name.

◆ log_sources_count()

static uint32_t log_sources_count ( void  )
inlinestatic

Get number of registered sources.

◆ log_string_sync()

void log_string_sync ( struct log_msg_ids  src_level,
const char *  fmt,
  ... 
)

Process log message synchronously.

Parameters
src_levelLog message details.
fmtString to format.
...Variable list of arguments.