Zephyr API Documentation 4.4.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
log_output.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_
7#define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_
8
10#include <zephyr/sys/util.h>
11#include <stdarg.h>
12#include <zephyr/sys/atomic.h>
13#include <zephyr/kernel.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
25
29
33#define LOG_OUTPUT_FLAG_COLORS BIT(0)
34
36#define LOG_OUTPUT_FLAG_TIMESTAMP BIT(1)
37
39#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP BIT(2)
40
42#define LOG_OUTPUT_FLAG_LEVEL BIT(3)
43
45#define LOG_OUTPUT_FLAG_CRLF_NONE BIT(4)
46
48#define LOG_OUTPUT_FLAG_CRLF_LFONLY BIT(5)
49
52#define LOG_OUTPUT_FLAG_FORMAT_SYSLOG BIT(6)
53
55#define LOG_OUTPUT_FLAG_THREAD BIT(7)
56
58#define LOG_OUTPUT_FLAG_SKIP_SOURCE BIT(8)
59
61#define LOG_OUTPUT_FLAG_CORE BIT(9)
62
64
68#define LOG_OUTPUT_TEXT 0
69
70#define LOG_OUTPUT_SYST 1
71
72#define LOG_OUTPUT_DICT 2
73
74#define LOG_OUTPUT_CUSTOM 3
75
89typedef int (*log_output_func_t)(uint8_t *buf, size_t size, void *ctx);
90
91/* @brief Control block structure for log_output instance. */
97
105
115typedef void (*log_format_func_t)(const struct log_output *output,
116 struct log_msg *msg, uint32_t flags);
117
122
130#define LOG_OUTPUT_DEFINE(_name, _func, _buf, _size) \
131 static struct log_output_control_block _name##_control_block; \
132 static const struct log_output _name = { \
133 .func = _func, \
134 .control_block = &_name##_control_block, \
135 .buf = _buf, \
136 .size = _size, \
137 }
138
149 struct log_msg *msg, uint32_t flags);
150
166 log_timestamp_t timestamp,
167 const char *domain,
168 const char *source,
169 k_tid_t tid,
170 uint8_t core_id,
171 uint8_t level,
172 const uint8_t *package,
173 const uint8_t *data,
174 size_t data_len,
176
187 struct log_msg *msg, uint32_t flags);
188
196void log_output_dropped_process(const struct log_output *output, uint32_t cnt);
197
205static inline void log_output_write(log_output_func_t outf, uint8_t *buf, size_t len, void *ctx)
206{
207 int processed;
208
209 while (len != 0) {
210 processed = outf(buf, len, ctx);
211 len -= processed;
212 buf += processed;
213 }
214}
215
220static inline void log_output_flush(const struct log_output *output)
221{
222 log_output_write(output->func, output->buf, output->control_block->offset,
223 output->control_block->ctx);
224 output->control_block->offset = 0;
225}
226
232static inline void log_output_ctx_set(const struct log_output *output,
233 void *ctx)
234{
235 output->control_block->ctx = ctx;
236}
237
243static inline void log_output_hostname_set(const struct log_output *output,
244 const char *hostname)
245{
246 output->control_block->hostname = hostname;
247}
248
254
262
266
267
268#ifdef __cplusplus
269}
270#endif
271
272#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_ */
long atomic_t
Definition atomic_types.h:15
void log_output_dropped_process(const struct log_output *output, uint32_t cnt)
Process dropped messages indication.
void(* log_format_func_t)(const struct log_output *output, struct log_msg *msg, uint32_t flags)
Typedef of the function pointer table "format_table".
Definition log_output.h:115
static void log_output_write(log_output_func_t outf, uint8_t *buf, size_t len, void *ctx)
Write to the output buffer.
Definition log_output.h:205
static void log_output_hostname_set(const struct log_output *output, const char *hostname)
Function for setting hostname of this device.
Definition log_output.h:243
void log_output_timestamp_freq_set(uint32_t freq)
Set timestamp frequency.
void log_output_process(const struct log_output *log_output, log_timestamp_t timestamp, const char *domain, const char *source, k_tid_t tid, uint8_t core_id, uint8_t level, const uint8_t *package, const uint8_t *data, size_t data_len, uint32_t flags)
Process input data to a readable string.
void log_output_msg_process(const struct log_output *log_output, struct log_msg *msg, uint32_t flags)
Process log messages v2 to readable strings.
uint64_t log_output_timestamp_to_us(log_timestamp_t timestamp)
Convert timestamp of the message to us.
static void log_output_ctx_set(const struct log_output *output, void *ctx)
Function for setting user context passed to the output function.
Definition log_output.h:232
log_format_func_t log_format_func_t_get(uint32_t log_type)
Declaration of the get routine for function pointer table format_table.
void log_output_msg_syst_process(const struct log_output *log_output, struct log_msg *msg, uint32_t flags)
Process log messages v2 to SYS-T format.
static void log_output_flush(const struct log_output *output)
Flush output buffer.
Definition log_output.h:220
int(* log_output_func_t)(uint8_t *buf, size_t size, void *ctx)
Prototype of the function processing output data.
Definition log_output.h:89
struct k_thread * k_tid_t
Definition thread.h:383
Public kernel APIs.
uint32_t log_timestamp_t
Definition log_msg.h:36
flags
Definition parser.h:97
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Definition log_msg.h:97
uint8_t data[]
Definition log_msg.h:103
Definition log_output.h:92
atomic_t offset
Definition log_output.h:93
const char * hostname
Definition log_output.h:95
void * ctx
Definition log_output.h:94
Log_output instance structure.
Definition log_output.h:99
struct log_output_control_block * control_block
Definition log_output.h:101
log_output_func_t func
Definition log_output.h:100
uint8_t * buf
Definition log_output.h:102
size_t size
Definition log_output.h:103
Misc utilities.