Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Log message API

Log message API. More...

Data Structures

struct  log_msg_ids
 Part of log message header identifying source and level. More...
 
struct  log_msg_generic_hdr
 
struct  log_msg_std_hdr
 
struct  log_msg_hexdump_hdr
 
struct  log_msg_hdr
 
union  log_msg_head_data
 Data part of log message. More...
 
struct  log_msg_ext_head_data
 Data part of extended log message. More...
 
struct  log_msg
 Log message structure. More...
 
struct  log_msg_cont
 Chunks following message head when message is extended. More...
 
union  log_msg_chunk
 Log message. More...
 

Macros

#define LOG_MAX_NARGS   15
 Maximum number of arguments in the standard log entry. More...
 
#define LOG_MSG_NARGS_SINGLE_CHUNK   3U
 Number of arguments in the log entry which fits in one chunk. More...
 
#define LOG_MSG_NARGS_HEAD_CHUNK    (LOG_MSG_NARGS_SINGLE_CHUNK - (sizeof(void *)/sizeof(log_arg_t)))
 Number of arguments in the head of extended standard log message.. More...
 
#define LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK    (LOG_MSG_NARGS_SINGLE_CHUNK * sizeof(log_arg_t))
 Maximal amount of bytes in the hexdump entry which fits in one chunk. More...
 
#define LOG_MSG_HEXDUMP_BYTES_HEAD_CHUNK    (LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK - sizeof(void *))
 Number of bytes in the first chunk of hexdump message if message consists of more than one chunk. More...
 
#define HEXDUMP_BYTES_CONT_MSG    (sizeof(struct log_msg) - sizeof(void *))
 Number of bytes that can be stored in chunks following head chunk in hexdump log message. More...
 
#define ARGS_CONT_MSG   (HEXDUMP_BYTES_CONT_MSG / sizeof(log_arg_t))
 
#define LOG_MSG_TYPE_STD   0U
 Flag indicating standard log message. More...
 
#define LOG_MSG_TYPE_HEXDUMP   1
 Flag indicating hexdump log message. More...
 
#define COMMON_PARAM_HDR()
 Common part of log message header. More...
 
#define LOG_MSG_HEXDUMP_LENGTH_BITS   14
 Number of bits used for storing length of hexdump log message. More...
 
#define LOG_MSG_HEXDUMP_MAX_LENGTH   (BIT(LOG_MSG_HEXDUMP_LENGTH_BITS) - 1)
 Maximum length of log hexdump message. More...
 

Typedefs

typedef unsigned long log_arg_t
 Log argument type. More...
 

Functions

void log_msg_pool_init (void)
 Function for initialization of the log message pool. More...
 
void log_msg_get (struct log_msg *msg)
 Function for indicating that message is in use. More...
 
void log_msg_put (struct log_msg *msg)
 Function for indicating that message is no longer in use. More...
 
static uint32_t log_msg_domain_id_get (struct log_msg *msg)
 Get domain ID of the message. More...
 
static uint32_t log_msg_source_id_get (struct log_msg *msg)
 Get source ID (module or instance) of the message. More...
 
static uint32_t log_msg_level_get (struct log_msg *msg)
 Get severity level of the message. More...
 
static uint32_t log_msg_timestamp_get (struct log_msg *msg)
 Get timestamp of the message. More...
 
static bool log_msg_is_std (struct log_msg *msg)
 Check if message is of standard type. More...
 
uint32_t log_msg_nargs_get (struct log_msg *msg)
 Returns number of arguments in standard log message. More...
 
log_arg_t log_msg_arg_get (struct log_msg *msg, uint32_t arg_idx)
 Gets argument from standard log message. More...
 
const char * log_msg_str_get (struct log_msg *msg)
 Gets pointer to the unformatted string from standard log message. More...
 
struct log_msglog_msg_hexdump_create (const char *str, const uint8_t *data, uint32_t length)
 Allocates chunks for hexdump message and copies the data. More...
 
void log_msg_hexdump_data_put (struct log_msg *msg, uint8_t *data, size_t *length, size_t offset)
 Put data into hexdump log message. More...
 
void log_msg_hexdump_data_get (struct log_msg *msg, uint8_t *data, size_t *length, size_t offset)
 Get data from hexdump log message. More...
 
union log_msg_chunklog_msg_no_space_handle (void)
 
union log_msg_chunklog_msg_chunk_alloc (void)
 Allocate single chunk from the pool. More...
 
static struct log_msglog_msg_create_0 (const char *str)
 Create standard log message with no arguments. More...
 
static struct log_msglog_msg_create_1 (const char *str, log_arg_t arg1)
 Create standard log message with one argument. More...
 
static struct log_msglog_msg_create_2 (const char *str, log_arg_t arg1, log_arg_t arg2)
 Create standard log message with two arguments. More...
 
static struct log_msglog_msg_create_3 (const char *str, log_arg_t arg1, log_arg_t arg2, log_arg_t arg3)
 Create standard log message with three arguments. More...
 
struct log_msglog_msg_create_n (const char *str, log_arg_t *args, uint32_t nargs)
 Create standard log message with variable number of arguments. More...
 
uint32_t log_msg_mem_get_free (void)
 Get number of free blocks from the log mem pool. More...
 
uint32_t log_msg_mem_get_used (void)
 Get number of used blocks from the log mem pool. More...
 
uint32_t log_msg_mem_get_max_used (void)
 Get max used blocks from the log mem pool. More...
 

Detailed Description

Log message API.

Macro Definition Documentation

◆ ARGS_CONT_MSG

#define ARGS_CONT_MSG   (HEXDUMP_BYTES_CONT_MSG / sizeof(log_arg_t))

◆ COMMON_PARAM_HDR

#define COMMON_PARAM_HDR ( )

#include <include/logging/log_msg.h>

Value:
uint16_t type : 1; \
uint16_t ext : 1
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59

Common part of log message header.

◆ HEXDUMP_BYTES_CONT_MSG

#define HEXDUMP_BYTES_CONT_MSG    (sizeof(struct log_msg) - sizeof(void *))

#include <include/logging/log_msg.h>

Number of bytes that can be stored in chunks following head chunk in hexdump log message.

◆ LOG_MAX_NARGS

#define LOG_MAX_NARGS   15

#include <include/logging/log_msg.h>

Maximum number of arguments in the standard log entry.

It is limited by 4 bit nargs field in the log message.

◆ LOG_MSG_HEXDUMP_BYTES_HEAD_CHUNK

#define LOG_MSG_HEXDUMP_BYTES_HEAD_CHUNK    (LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK - sizeof(void *))

#include <include/logging/log_msg.h>

Number of bytes in the first chunk of hexdump message if message consists of more than one chunk.

◆ LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK

#define LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK    (LOG_MSG_NARGS_SINGLE_CHUNK * sizeof(log_arg_t))

#include <include/logging/log_msg.h>

Maximal amount of bytes in the hexdump entry which fits in one chunk.

◆ LOG_MSG_HEXDUMP_LENGTH_BITS

#define LOG_MSG_HEXDUMP_LENGTH_BITS   14

#include <include/logging/log_msg.h>

Number of bits used for storing length of hexdump log message.

◆ LOG_MSG_HEXDUMP_MAX_LENGTH

#define LOG_MSG_HEXDUMP_MAX_LENGTH   (BIT(LOG_MSG_HEXDUMP_LENGTH_BITS) - 1)

#include <include/logging/log_msg.h>

Maximum length of log hexdump message.

◆ LOG_MSG_NARGS_HEAD_CHUNK

#define LOG_MSG_NARGS_HEAD_CHUNK    (LOG_MSG_NARGS_SINGLE_CHUNK - (sizeof(void *)/sizeof(log_arg_t)))

#include <include/logging/log_msg.h>

Number of arguments in the head of extended standard log message..

◆ LOG_MSG_NARGS_SINGLE_CHUNK

#define LOG_MSG_NARGS_SINGLE_CHUNK   3U

#include <include/logging/log_msg.h>

Number of arguments in the log entry which fits in one chunk.

◆ LOG_MSG_TYPE_HEXDUMP

#define LOG_MSG_TYPE_HEXDUMP   1

#include <include/logging/log_msg.h>

Flag indicating hexdump log message.

◆ LOG_MSG_TYPE_STD

#define LOG_MSG_TYPE_STD   0U

#include <include/logging/log_msg.h>

Flag indicating standard log message.

Typedef Documentation

◆ log_arg_t

typedef unsigned long log_arg_t

#include <include/logging/log_msg.h>

Log argument type.

Should preferably be equivalent to a native word size.

Function Documentation

◆ log_msg_arg_get()

log_arg_t log_msg_arg_get ( struct log_msg msg,
uint32_t  arg_idx 
)

#include <include/logging/log_msg.h>

Gets argument from standard log message.

Parameters
msgStandard log message.
arg_idxArgument index.
Returns
Argument value or 0 if arg_idx exceeds number of arguments in the message.

◆ log_msg_chunk_alloc()

union log_msg_chunk * log_msg_chunk_alloc ( void  )

#include <include/logging/log_msg.h>

Allocate single chunk from the pool.

Returns
Pointer to the allocated chunk or NULL if failed to allocate.

◆ log_msg_create_0()

static struct log_msg * log_msg_create_0 ( const char *  str)
inlinestatic

#include <include/logging/log_msg.h>

Create standard log message with no arguments.

Function resets header and sets following fields:

  • message type
  • string pointer
Returns
Pointer to allocated head of the message or NULL.

◆ log_msg_create_1()

static struct log_msg * log_msg_create_1 ( const char *  str,
log_arg_t  arg1 
)
inlinestatic

#include <include/logging/log_msg.h>

Create standard log message with one argument.

Function resets header and sets following fields:

  • message type
  • string pointer
  • number of arguments
  • argument
Parameters
strString.
arg1Argument.
Returns
Pointer to allocated head of the message or NULL.

◆ log_msg_create_2()

static struct log_msg * log_msg_create_2 ( const char *  str,
log_arg_t  arg1,
log_arg_t  arg2 
)
inlinestatic

#include <include/logging/log_msg.h>

Create standard log message with two arguments.

Function resets header and sets following fields:

  • message type
  • string pointer
  • number of arguments
  • arguments
Parameters
strString.
arg1Argument 1.
arg2Argument 2.
Returns
Pointer to allocated head of the message or NULL.

◆ log_msg_create_3()

static struct log_msg * log_msg_create_3 ( const char *  str,
log_arg_t  arg1,
log_arg_t  arg2,
log_arg_t  arg3 
)
inlinestatic

#include <include/logging/log_msg.h>

Create standard log message with three arguments.

Function resets header and sets following fields:

  • message type
  • string pointer
  • number of arguments
  • arguments
Parameters
strString.
arg1Argument 1.
arg2Argument 2.
arg3Argument 3.
Returns
Pointer to allocated head of the message or NULL.

◆ log_msg_create_n()

struct log_msg * log_msg_create_n ( const char *  str,
log_arg_t args,
uint32_t  nargs 
)

#include <include/logging/log_msg.h>

Create standard log message with variable number of arguments.

Function resets header and sets following fields:

  • message type
  • string pointer
  • number of arguments
  • arguments
Parameters
strString.
argsArray with arguments.
nargsNumber of arguments.
Returns
Pointer to allocated head of the message or NULL.

◆ log_msg_domain_id_get()

static uint32_t log_msg_domain_id_get ( struct log_msg msg)
inlinestatic

#include <include/logging/log_msg.h>

Get domain ID of the message.

Parameters
msgMessage
Returns
Domain ID.

◆ log_msg_get()

void log_msg_get ( struct log_msg msg)

#include <include/logging/log_msg.h>

Function for indicating that message is in use.

Message can be used (read) by multiple users. Internal reference counter is atomically increased. See log_msg_put.

Parameters
msgMessage.

◆ log_msg_hexdump_create()

struct log_msg * log_msg_hexdump_create ( const char *  str,
const uint8_t data,
uint32_t  length 
)

#include <include/logging/log_msg.h>

Allocates chunks for hexdump message and copies the data.

Function resets header and sets following fields:

  • message type
  • length
Note
Allocation and partial filling is combined for performance reasons.
Parameters
strString.
dataData.
lengthData length.
Returns
Pointer to allocated head of the message or NULL

◆ log_msg_hexdump_data_get()

void log_msg_hexdump_data_get ( struct log_msg msg,
uint8_t data,
size_t *  length,
size_t  offset 
)

#include <include/logging/log_msg.h>

Get data from hexdump log message.

Parameters
[in]msgMessage.
[in]dataBuffer for data.
[in,out]lengthInput: requested amount. Output: actual amount.
[in]offsetOffset.

◆ log_msg_hexdump_data_put()

void log_msg_hexdump_data_put ( struct log_msg msg,
uint8_t data,
size_t *  length,
size_t  offset 
)

#include <include/logging/log_msg.h>

Put data into hexdump log message.

Parameters
[in]msgMessage.
[in]dataData to be copied.
[in,out]lengthInput: requested amount. Output: actual amount.
[in]offsetOffset.

◆ log_msg_is_std()

static bool log_msg_is_std ( struct log_msg msg)
inlinestatic

#include <include/logging/log_msg.h>

Check if message is of standard type.

Parameters
msgMessage
Return values
trueStandard message.
falseHexdump message.

◆ log_msg_level_get()

static uint32_t log_msg_level_get ( struct log_msg msg)
inlinestatic

#include <include/logging/log_msg.h>

Get severity level of the message.

Parameters
msgMessage
Returns
Severity message.

◆ log_msg_mem_get_free()

uint32_t log_msg_mem_get_free ( void  )

#include <include/logging/log_msg.h>

Get number of free blocks from the log mem pool.

◆ log_msg_mem_get_max_used()

uint32_t log_msg_mem_get_max_used ( void  )

#include <include/logging/log_msg.h>

Get max used blocks from the log mem pool.

◆ log_msg_mem_get_used()

uint32_t log_msg_mem_get_used ( void  )

#include <include/logging/log_msg.h>

Get number of used blocks from the log mem pool.

◆ log_msg_nargs_get()

uint32_t log_msg_nargs_get ( struct log_msg msg)

#include <include/logging/log_msg.h>

Returns number of arguments in standard log message.

Parameters
msgStandard log message.
Returns
Number of arguments.

◆ log_msg_no_space_handle()

union log_msg_chunk * log_msg_no_space_handle ( void  )

◆ log_msg_pool_init()

void log_msg_pool_init ( void  )

#include <include/logging/log_msg.h>

Function for initialization of the log message pool.

◆ log_msg_put()

void log_msg_put ( struct log_msg msg)

#include <include/logging/log_msg.h>

Function for indicating that message is no longer in use.

Internal reference counter is atomically decreased. If reference counter equals 0 message is freed.

Parameters
msgMessage.

◆ log_msg_source_id_get()

static uint32_t log_msg_source_id_get ( struct log_msg msg)
inlinestatic

#include <include/logging/log_msg.h>

Get source ID (module or instance) of the message.

Parameters
msgMessage
Returns
Source ID.

◆ log_msg_str_get()

const char * log_msg_str_get ( struct log_msg msg)

#include <include/logging/log_msg.h>

Gets pointer to the unformatted string from standard log message.

Parameters
msgStandard log message.
Returns
Pointer to the string.

◆ log_msg_timestamp_get()

static uint32_t log_msg_timestamp_get ( struct log_msg msg)
inlinestatic

#include <include/logging/log_msg.h>

Get timestamp of the message.

Parameters
msgMessage
Returns
Timestamp value.