Zephyr Project API  3.3.0
A Scalable Open Source RTOS
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
14#ifdef __cplusplus
15extern "C" {
16#endif
17
32#define LOG_OUTPUT_FLAG_COLORS BIT(0)
33
35#define LOG_OUTPUT_FLAG_TIMESTAMP BIT(1)
36
38#define LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP BIT(2)
39
41#define LOG_OUTPUT_FLAG_LEVEL BIT(3)
42
44#define LOG_OUTPUT_FLAG_CRLF_NONE BIT(4)
45
47#define LOG_OUTPUT_FLAG_CRLF_LFONLY BIT(5)
48
51#define LOG_OUTPUT_FLAG_FORMAT_SYSLOG BIT(6)
52
58#define LOG_OUTPUT_TEXT 0
59
60#define LOG_OUTPUT_SYST 1
61
62#define LOG_OUTPUT_DICT 2
63
64#define LOG_OUTPUT_CUSTOM 3
65
79typedef int (*log_output_func_t)(uint8_t *buf, size_t size, void *ctx);
80
81/* @brief Control block structure for log_output instance. */
84 void *ctx;
85 const char *hostname;
86};
87
89struct log_output {
93 size_t size;
94};
95
105typedef void (*log_format_func_t)(const struct log_output *output,
106 struct log_msg *msg, uint32_t flags);
107
112
120#define LOG_OUTPUT_DEFINE(_name, _func, _buf, _size) \
121 static struct log_output_control_block _name##_control_block; \
122 static const struct log_output _name = { \
123 .func = _func, \
124 .control_block = &_name##_control_block, \
125 .buf = _buf, \
126 .size = _size, \
127 }
128
139 struct log_msg *msg, uint32_t flags);
140
154 log_timestamp_t timestamp,
155 const char *domain,
156 const char *source,
157 uint8_t level,
158 const uint8_t *package,
159 const uint8_t *data,
160 size_t data_len,
162
173 struct log_msg *msg, uint32_t flags);
174
182void log_output_dropped_process(const struct log_output *output, uint32_t cnt);
183
188void log_output_flush(const struct log_output *output);
189
195static inline void log_output_ctx_set(const struct log_output *output,
196 void *ctx)
197{
198 output->control_block->ctx = ctx;
199}
200
206static inline void log_output_hostname_set(const struct log_output *output,
207 const char *hostname)
208{
209 output->control_block->hostname = hostname;
210}
211
217
225
231#ifdef __cplusplus
232}
233#endif
234
235#endif /* ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_H_ */
long atomic_t
Definition: atomic.h:22
void log_output_dropped_process(const struct log_output *output, uint32_t cnt)
Process dropped messages indication.
void log_output_flush(const struct log_output *output)
Flush output buffer.
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:105
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:206
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, 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 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:195
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.
uint64_t log_output_timestamp_to_us(uint32_t timestamp)
Convert timestamp of the message to us.
int(* log_output_func_t)(uint8_t *buf, size_t size, void *ctx)
Prototype of the function processing output data.
Definition: log_output.h:79
uint32_t log_timestamp_t
Definition: log_msg.h:35
flags
Definition: parser.h:96
__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:88
Definition: log_output.h:82
atomic_t offset
Definition: log_output.h:83
const char * hostname
Definition: log_output.h:85
void * ctx
Definition: log_output.h:84
Log_output instance structure.
Definition: log_output.h:89
struct log_output_control_block * control_block
Definition: log_output.h:91
log_output_func_t func
Definition: log_output.h:90
uint8_t * buf
Definition: log_output.h:92
size_t size
Definition: log_output.h:93
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static void msg(uint64_t c64)
Definition: main.c:17
Misc utilities.