Zephyr API Documentation 4.4.99
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
12
13#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_
14#define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_
15
17#include <zephyr/sys/util.h>
18#include <stdarg.h>
19#include <zephyr/sys/atomic.h>
20#include <zephyr/kernel.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
32
36
40#define LOG_OUTPUT_FLAG_COLORS BIT(0)
41
43#define LOG_OUTPUT_FLAG_TIMESTAMP BIT(1)
44
46#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP BIT(2)
47
49#define LOG_OUTPUT_FLAG_LEVEL BIT(3)
50
52#define LOG_OUTPUT_FLAG_CRLF_NONE BIT(4)
53
55#define LOG_OUTPUT_FLAG_CRLF_LFONLY BIT(5)
56
59#define LOG_OUTPUT_FLAG_FORMAT_SYSLOG BIT(6)
60
62#define LOG_OUTPUT_FLAG_THREAD BIT(7)
63
65#define LOG_OUTPUT_FLAG_SKIP_SOURCE BIT(8)
66
68#define LOG_OUTPUT_FLAG_CORE BIT(9)
69
71
79
81#define LOG_OUTPUT_TEXT 0
82
84#define LOG_OUTPUT_SYST 1
85
87#define LOG_OUTPUT_DICT 2
88
90#define LOG_OUTPUT_CUSTOM 3
91
93
107typedef int (*log_output_func_t)(uint8_t *buf, size_t size, void *ctx);
108
112 atomic_t offset;
113 void *ctx;
114 const char *hostname;
116};
117
125
135typedef void (*log_format_func_t)(const struct log_output *output,
136 struct log_msg *msg, uint32_t flags);
137
142
150#define LOG_OUTPUT_DEFINE(_name, _func, _buf, _size) \
151 static struct log_output_control_block _name##_control_block; \
152 static const struct log_output _name = { \
153 .func = _func, \
154 .control_block = &_name##_control_block, \
155 .buf = _buf, \
156 .size = _size, \
157 }
158
169 struct log_msg *msg, uint32_t flags);
170
186 log_timestamp_t timestamp,
187 const char *domain,
188 const char *source,
189 k_tid_t tid,
190 uint8_t core_id,
191 uint8_t level,
192 const uint8_t *package,
193 const uint8_t *data,
194 size_t data_len,
196
207 struct log_msg *msg, uint32_t flags);
208
216void log_output_dropped_process(const struct log_output *output, uint32_t cnt);
217
225static inline void log_output_write(log_output_func_t outf, uint8_t *buf, size_t len, void *ctx)
226{
227 int processed;
228
229 while (len != 0) {
230 processed = outf(buf, len, ctx);
231 len -= processed;
232 buf += processed;
233 }
234}
235
240static inline void log_output_flush(const struct log_output *output)
241{
242 log_output_write(output->func, output->buf, output->control_block->offset,
243 output->control_block->ctx);
244 output->control_block->offset = 0;
245}
246
252static inline void log_output_ctx_set(const struct log_output *output,
253 void *ctx)
254{
255 output->control_block->ctx = ctx;
256}
257
263static inline void log_output_hostname_set(const struct log_output *output,
264 const char *hostname)
265{
266 output->control_block->hostname = hostname;
267}
268
274
282
286
287
288#ifdef __cplusplus
289}
290#endif
291
292#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_ */
Header file for the Atomic operations API.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
uint32_t log_timestamp_t
Timestamp value associated with a log message.
Definition log_msg.h:54
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:135
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:225
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:263
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:252
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:240
int(* log_output_func_t)(uint8_t *buf, size_t size, void *ctx)
Prototype of the function processing output data.
Definition log_output.h:107
Public kernel APIs.
Header file for log messages.
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
Run-time control block for a Log output instance.
Definition log_output.h:110
Log output instance.
Definition log_output.h:119
struct log_output_control_block * control_block
Run-time control block.
Definition log_output.h:121
log_output_func_t func
Function called to write formatted output.
Definition log_output.h:120
uint8_t * buf
Buffer holding formatted output before it is written.
Definition log_output.h:122
size_t size
Size of log_output::buf, in bytes.
Definition log_output.h:123
Misc utilities.
struct k_thread * k_tid_t
Definition thread.h:383