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

Log output API. More...

Data Structures

struct  log_output_control_block
 
struct  log_output
 Log_output instance structure. More...
 

Macros

#define LOG_OUTPUT_FLAG_COLORS   BIT(0)
 Flag forcing ANSI escape code colors, red (errors), yellow (warnings). More...
 
#define LOG_OUTPUT_FLAG_TIMESTAMP   BIT(1)
 Flag forcing timestamp. More...
 
#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP   BIT(2)
 Flag forcing timestamp formatting. More...
 
#define LOG_OUTPUT_FLAG_LEVEL   BIT(3)
 Flag forcing severity level prefix. More...
 
#define LOG_OUTPUT_FLAG_CRLF_NONE   BIT(4)
 Flag preventing the logger from adding CR and LF characters. More...
 
#define LOG_OUTPUT_FLAG_CRLF_LFONLY   BIT(5)
 Flag forcing a single LF character for line breaks. More...
 
#define LOG_OUTPUT_FLAG_FORMAT_SYSLOG   BIT(6)
 Flag forcing syslog format specified in RFC 5424. More...
 
#define LOG_OUTPUT_FLAG_FORMAT_SYST   BIT(7)
 Flag forcing syslog format specified in mipi sys-t. More...
 
#define LOG_OUTPUT_DEFINE(_name, _func, _buf, _size)
 Create log_output instance. More...
 

Typedefs

typedef int(* log_output_func_t) (uint8_t *buf, size_t size, void *ctx)
 Prototype of the function processing output data. More...
 

Functions

void log_output_msg_process (const struct log_output *output, struct log_msg *msg, uint32_t flags)
 Process log messages to readable strings. More...
 
void log_output_msg2_process (const struct log_output *log_output, struct log_msg2 *msg, uint32_t flags)
 Process log messages v2 to readable strings. More...
 
void log_output_string (const struct log_output *output, struct log_msg_ids src_level, uint32_t timestamp, const char *fmt, va_list ap, uint32_t flags)
 Process log string. More...
 
void log_output_hexdump (const struct log_output *output, struct log_msg_ids src_level, uint32_t timestamp, const char *metadata, const uint8_t *data, uint32_t length, uint32_t flags)
 Process log hexdump. More...
 
void log_output_dropped_process (const struct log_output *output, uint32_t cnt)
 Process dropped messages indication. More...
 
void log_output_flush (const struct log_output *output)
 Flush output buffer. More...
 
static void log_output_ctx_set (const struct log_output *output, void *ctx)
 Function for setting user context passed to the output function. More...
 
static void log_output_hostname_set (const struct log_output *output, const char *hostname)
 Function for setting hostname of this device. More...
 
void log_output_timestamp_freq_set (uint32_t freq)
 Set timestamp frequency. More...
 
uint64_t log_output_timestamp_to_us (uint32_t timestamp)
 Convert timestamp of the message to us. More...
 

Detailed Description

Log output API.

Macro Definition Documentation

◆ LOG_OUTPUT_DEFINE

#define LOG_OUTPUT_DEFINE (   _name,
  _func,
  _buf,
  _size 
)

#include <include/logging/log_output.h>

Value:
static struct log_output_control_block _name##_control_block; \
static const struct log_output _name = { \
.func = _func, \
.control_block = &_name##_control_block, \
.buf = _buf, \
.size = _size, \
}
Definition: log_output.h:69
Log_output instance structure.
Definition: log_output.h:76
log_output_func_t func
Definition: log_output.h:77
uint8_t * buf
Definition: log_output.h:79

Create log_output instance.

Parameters
_nameInstance name.
_funcFunction for processing output data.
_bufPointer to the output buffer.
_sizeSize of the output buffer.

◆ LOG_OUTPUT_FLAG_COLORS

#define LOG_OUTPUT_FLAG_COLORS   BIT(0)

#include <include/logging/log_output.h>

Flag forcing ANSI escape code colors, red (errors), yellow (warnings).

◆ LOG_OUTPUT_FLAG_CRLF_LFONLY

#define LOG_OUTPUT_FLAG_CRLF_LFONLY   BIT(5)

#include <include/logging/log_output.h>

Flag forcing a single LF character for line breaks.

◆ LOG_OUTPUT_FLAG_CRLF_NONE

#define LOG_OUTPUT_FLAG_CRLF_NONE   BIT(4)

#include <include/logging/log_output.h>

Flag preventing the logger from adding CR and LF characters.

◆ LOG_OUTPUT_FLAG_FORMAT_SYSLOG

#define LOG_OUTPUT_FLAG_FORMAT_SYSLOG   BIT(6)

#include <include/logging/log_output.h>

Flag forcing syslog format specified in RFC 5424.

◆ LOG_OUTPUT_FLAG_FORMAT_SYST

#define LOG_OUTPUT_FLAG_FORMAT_SYST   BIT(7)

#include <include/logging/log_output.h>

Flag forcing syslog format specified in mipi sys-t.

◆ LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP

#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP   BIT(2)

#include <include/logging/log_output.h>

Flag forcing timestamp formatting.

◆ LOG_OUTPUT_FLAG_LEVEL

#define LOG_OUTPUT_FLAG_LEVEL   BIT(3)

#include <include/logging/log_output.h>

Flag forcing severity level prefix.

◆ LOG_OUTPUT_FLAG_TIMESTAMP

#define LOG_OUTPUT_FLAG_TIMESTAMP   BIT(1)

#include <include/logging/log_output.h>

Flag forcing timestamp.

Typedef Documentation

◆ log_output_func_t

typedef int(* log_output_func_t) (uint8_t *buf, size_t size, void *ctx)

#include <include/logging/log_output.h>

Prototype of the function processing output data.

Parameters
bufThe buffer data.
sizeThe buffer size.
ctxUser context.
Returns
Number of bytes processed, dropped or discarded.
Note
If the log output function cannot process all of the data, it is its responsibility to mark them as dropped or discarded by returning the corresponding number of bytes dropped or discarded to the caller.

Function Documentation

◆ log_output_ctx_set()

static void log_output_ctx_set ( const struct log_output output,
void ctx 
)
inlinestatic

#include <include/logging/log_output.h>

Function for setting user context passed to the output function.

Parameters
outputPointer to the log output instance.
ctxUser context.

◆ log_output_dropped_process()

void log_output_dropped_process ( const struct log_output output,
uint32_t  cnt 
)

#include <include/logging/log_output.h>

Process dropped messages indication.

Function prints error message indicating lost log messages.

Parameters
outputPointer to the log output instance.
cntNumber of dropped messages.

◆ log_output_flush()

void log_output_flush ( const struct log_output output)

#include <include/logging/log_output.h>

Flush output buffer.

Parameters
outputPointer to the log output instance.

◆ log_output_hexdump()

void log_output_hexdump ( const struct log_output output,
struct log_msg_ids  src_level,
uint32_t  timestamp,
const char *  metadata,
const uint8_t data,
uint32_t  length,
uint32_t  flags 
)

#include <include/logging/log_output.h>

Process log hexdump.

Function is formatting provided hexdump adding optional prefixes and postfixes.

Parameters
outputPointer to log_output instance.
src_levelLog source and level structure.
timestampTimestamp.
metadataString.
dataData.
lengthData length.
flagsOptional flags.

◆ log_output_hostname_set()

static void log_output_hostname_set ( const struct log_output output,
const char *  hostname 
)
inlinestatic

#include <include/logging/log_output.h>

Function for setting hostname of this device.

Parameters
outputPointer to the log output instance.
hostnameHostname of this device

◆ log_output_msg2_process()

void log_output_msg2_process ( const struct log_output log_output,
struct log_msg2 msg,
uint32_t  flags 
)

#include <include/logging/log_output.h>

Process log messages v2 to readable strings.

Function is using provided context with the buffer and output function to process formatted string and output the data.

Parameters
log_outputPointer to the log output instance.
msgLog message.
flagsOptional flags.

◆ log_output_msg_process()

void log_output_msg_process ( const struct log_output output,
struct log_msg msg,
uint32_t  flags 
)

#include <include/logging/log_output.h>

Process log messages to readable strings.

Function is using provided context with the buffer and output function to process formatted string and output the data.

Parameters
outputPointer to the log output instance.
msgLog message.
flagsOptional flags.

◆ log_output_string()

void log_output_string ( const struct log_output output,
struct log_msg_ids  src_level,
uint32_t  timestamp,
const char *  fmt,
va_list  ap,
uint32_t  flags 
)

#include <include/logging/log_output.h>

Process log string.

Function is formatting provided string adding optional prefixes and postfixes.

Parameters
outputPointer to log_output instance.
src_levelLog source and level structure.
timestampTimestamp.
fmtString.
apString arguments.
flagsOptional flags.

◆ log_output_timestamp_freq_set()

void log_output_timestamp_freq_set ( uint32_t  freq)

#include <include/logging/log_output.h>

Set timestamp frequency.

Parameters
freqFrequency in Hz.

◆ log_output_timestamp_to_us()

uint64_t log_output_timestamp_to_us ( uint32_t  timestamp)

#include <include/logging/log_output.h>

Convert timestamp of the message to us.

Parameters
timestampMessage timestamp
Returns
Timestamp value in us.