Line data Source code
1 0 : /* 2 : * Copyright (c) 2021 Converge 3 : * Copyright (c) 2023 Nobleo Technology 4 : * 5 : * SPDX-License-Identifier: Apache-2.0 6 : */ 7 : #ifndef ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_CUSTOM_H_ 8 : #define ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_CUSTOM_H_ 9 : 10 : #include <zephyr/logging/log_output.h> 11 : 12 : #ifdef __cplusplus 13 : extern "C" { 14 : #endif 15 : 16 : /** @brief Custom logging output formatting. 17 : * @ingroup log_output 18 : * @{ 19 : */ 20 : 21 : /** @brief Process log messages from an external output function set with 22 : * log_custom_output_msg_set 23 : * 24 : * Function is using provided context with the buffer and output function to 25 : * process formatted string and output the data. 26 : * 27 : * @param log_output Pointer to the log output instance. 28 : * @param msg Log message. 29 : * @param flags Optional flags. 30 : */ 31 1 : void log_custom_output_msg_process(const struct log_output *log_output, 32 : struct log_msg *msg, uint32_t flags); 33 : 34 : /** @brief Set the formatting log function that will be applied with LOG_OUTPUT_CUSTOM 35 : * 36 : * @param format Pointer to the external formatter function 37 : */ 38 1 : void log_custom_output_msg_set(log_format_func_t format); 39 : 40 : 41 : /** 42 : * @brief Prototype of a printer function that can print the given timestamp 43 : * into a specific logger instance. 44 : * 45 : * Example usage: 46 : * @code{.c} 47 : * log_timestamp_printer_t *printer = ...; 48 : * printer(log_instance, "%02u:%02u", hours, minutes); 49 : * @endcode 50 : * 51 : * @param output The logger instance to write to 52 : * @param fmt The format string 53 : * @param ... optional arguments for the format string 54 : */ 55 1 : typedef int (*log_timestamp_printer_t)(const struct log_output *output, const char *fmt, ...); 56 : 57 : /** 58 : * @brief Prototype of the function that will apply custom formatting 59 : * to a timestamp when LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP 60 : * 61 : * Example function: 62 : * @code{.c} 63 : * int custom_timestamp_formatter(const struct log_output* output, 64 : * const log_timestamp_t timestamp, 65 : * const log_timestamp_printer_t printer) { 66 : * return printer(output, "%d ", timestamp); 67 : * } 68 : * @endcode 69 : * 70 : * @param output The logger instance to write to 71 : * @param timestamp 72 : * @param printer The printing function to use when formatting the timestamp. 73 : */ 74 1 : typedef int (*log_timestamp_format_func_t)(const struct log_output *output, 75 : const log_timestamp_t timestamp, 76 : const log_timestamp_printer_t printer); 77 : 78 : /** @brief Format the timestamp with a external function. 79 : * 80 : * Function is using provided context with the buffer and output function to 81 : * process formatted string and output the data. 82 : * 83 : * @param output Pointer to the log output instance. 84 : * @param timestamp 85 : * @param printer The printing function to use when formatting the timestamp. 86 : */ 87 1 : int log_custom_timestamp_print(const struct log_output *output, const log_timestamp_t timestamp, 88 : const log_timestamp_printer_t printer); 89 : 90 : /** @brief Set the timestamp formatting function that will be applied 91 : * when LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP 92 : * 93 : * @param format Pointer to the external formatter function 94 : */ 95 1 : void log_custom_timestamp_set(log_timestamp_format_func_t format); 96 : 97 : /** 98 : * @} 99 : */ 100 : 101 : #ifdef __cplusplus 102 : } 103 : #endif 104 : 105 : #endif /* ZEPHYR_INCLUDE_LOGGING_LOG_OUTPUT_CUSTOM_H_ */