Zephyr API Documentation 4.5.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
16#include <errno.h>
18#include <zephyr/sys/util.h>
19#include <stdarg.h>
20#include <zephyr/sys/atomic.h>
21#include <zephyr/kernel.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
33
37
41#define LOG_OUTPUT_FLAG_COLORS BIT(0)
42
44#define LOG_OUTPUT_FLAG_TIMESTAMP BIT(1)
45
47#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP BIT(2)
48
50#define LOG_OUTPUT_FLAG_LEVEL BIT(3)
51
53#define LOG_OUTPUT_FLAG_CRLF_NONE BIT(4)
54
56#define LOG_OUTPUT_FLAG_CRLF_LFONLY BIT(5)
57
60#define LOG_OUTPUT_FLAG_FORMAT_SYSLOG BIT(6)
61
63#define LOG_OUTPUT_FLAG_THREAD BIT(7)
64
66#define LOG_OUTPUT_FLAG_SKIP_SOURCE BIT(8)
67
69#define LOG_OUTPUT_FLAG_CORE BIT(9)
70
72
74
82
84#define LOG_OUTPUT_TEXT 0
85
87#define LOG_OUTPUT_SYST 1
88
90#define LOG_OUTPUT_DICT 2
91
93#define LOG_OUTPUT_CUSTOM 3
94
96
110typedef int (*log_output_func_t)(uint8_t *buf, size_t size, void *ctx);
111
118typedef int (*log_output_get_available_t)(void *ctx);
119
123 atomic_t offset;
124 void *ctx;
125 const char *hostname;
126 struct k_spinlock lock;
128};
129
138
146typedef void (*log_format_func_t)(const struct log_output *output,
147 struct log_msg *msg, uint32_t flags);
148
153
161#define LOG_OUTPUT_DEFINE(_name, _func, _buf, _size) \
162 LOG_OUTPUT_EXT_DEFINE(_name, _func, NULL, _buf, _size)
163
172#define LOG_OUTPUT_EXT_DEFINE(_name, _func, _get_available, _buf, _size) \
173 static struct log_output_control_block _name##_control_block; \
174 static const struct log_output _name = { \
175 .func = _func, \
176 .get_available = _get_available, \
177 .control_block = &_name##_control_block, \
178 .buf = _buf, \
179 .size = _size, \
180 }
181
192 struct log_msg *msg, uint32_t flags);
193
209 log_timestamp_t timestamp,
210 const char *domain,
211 const char *source,
212 k_tid_t tid,
213 uint8_t core_id,
214 uint8_t level,
215 const uint8_t *package,
216 const uint8_t *data,
217 size_t data_len,
219
230 struct log_msg *msg, uint32_t flags);
231
239void log_output_dropped_process(const struct log_output *output, uint32_t cnt);
240
248static inline void log_output_write(log_output_func_t outf, uint8_t *buf, size_t len, void *ctx)
249{
250 int processed;
251
252 while (len != 0) {
253 processed = outf(buf, len, ctx);
254 len -= processed;
255 buf += processed;
256 }
257}
258
263static inline void log_output_flush(const struct log_output *output)
264{
265 log_output_write(output->func, output->buf, output->control_block->offset,
266 output->control_block->ctx);
267 output->control_block->offset = 0;
268}
269
275static inline void log_output_ctx_set(const struct log_output *output,
276 void *ctx)
277{
278 output->control_block->ctx = ctx;
279}
280
286static inline void log_output_hostname_set(const struct log_output *output,
287 const char *hostname)
288{
289 output->control_block->hostname = hostname;
290}
291
298static inline int log_output_get_available(const struct log_output *output)
299{
300 if (output->get_available == NULL) {
301 return -ENOTSUP;
302 }
303
304 return output->get_available(output->control_block->ctx);
305}
306
312
320
324
325
326#ifdef __cplusplus
327}
328#endif
329
330#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_ */
Header file for the Atomic operations API.
System error numbers.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
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:146
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:248
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:286
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.
static int log_output_get_available(const struct log_output *output)
Get available space in the output backend.
Definition log_output.h:298
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:275
log_format_func_t log_format_func_t_get(uint32_t log_type)
Declaration of the get routine for function pointer table format_table.
int(* log_output_get_available_t)(void *ctx)
Function pointer type for getting available output space.
Definition log_output.h:118
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:263
int(* log_output_func_t)(uint8_t *buf, size_t size, void *ctx)
Prototype of the function processing output data.
Definition log_output.h:110
#define ENOTSUP
Unsupported value.
Definition errno.h:115
struct k_thread * k_tid_t
Definition thread.h:414
Public kernel APIs.
Header file for log messages.
flags
Definition parser.h:86
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Kernel Spin Lock.
Definition spinlock.h:45
Run-time control block for a Log output instance.
Definition log_output.h:121
Log output instance.
Definition log_output.h:131
struct log_output_control_block * control_block
Run-time control block.
Definition log_output.h:134
log_output_get_available_t get_available
Get available output space.
Definition log_output.h:133
log_output_func_t func
Function called to write formatted output.
Definition log_output.h:132
uint8_t * buf
Buffer holding formatted output before it is written.
Definition log_output.h:135
size_t size
Size of log_output::buf, in bytes.
Definition log_output.h:136
Misc utilities.