Skip to content

Commit df683fd

Browse files
nordic-krchfabiobaltieri
authored andcommitted
logging: log_output: Move flushing and writing to the header
Move log_output_flush and log_output_write (renamed internal buffer_write() function) to the header as inline functions. Those function are used by log_output_dict.c and there are cases when log_output.c is not compiled in. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent f4335d2 commit df683fd

File tree

3 files changed

+33
-46
lines changed

3 files changed

+33
-46
lines changed

include/zephyr/logging/log_output.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,34 @@ void log_output_msg_syst_process(const struct log_output *log_output,
190190
*/
191191
void log_output_dropped_process(const struct log_output *output, uint32_t cnt);
192192

193+
/** @brief Write to the output buffer.
194+
*
195+
* @param outf Output function.
196+
* @param buf Buffer.
197+
* @param len Buffer length.
198+
* @param ctx Context passed to the %p outf.
199+
*/
200+
static inline void log_output_write(log_output_func_t outf, uint8_t *buf, size_t len, void *ctx)
201+
{
202+
int processed;
203+
204+
while (len != 0) {
205+
processed = outf(buf, len, ctx);
206+
len -= processed;
207+
buf += processed;
208+
}
209+
}
210+
193211
/** @brief Flush output buffer.
194212
*
195213
* @param output Pointer to the log output instance.
196214
*/
197-
void log_output_flush(const struct log_output *output);
215+
static inline void log_output_flush(const struct log_output *output)
216+
{
217+
log_output_write(output->func, output->buf, output->control_block->offset,
218+
output->control_block->ctx);
219+
output->control_block->offset = 0;
220+
}
198221

199222
/** @brief Function for setting user context passed to the output function.
200223
*

subsys/logging/log_output.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,6 @@ static int print_formatted(const struct log_output *output,
150150
return length;
151151
}
152152

153-
static void buffer_write(log_output_func_t outf, uint8_t *buf, size_t len,
154-
void *ctx)
155-
{
156-
int processed;
157-
158-
while (len != 0) {
159-
processed = outf(buf, len, ctx);
160-
len -= processed;
161-
buf += processed;
162-
}
163-
}
164-
165-
166-
void log_output_flush(const struct log_output *output)
167-
{
168-
buffer_write(output->func, output->buf,
169-
output->control_block->offset,
170-
output->control_block->ctx);
171-
172-
output->control_block->offset = 0;
173-
}
174-
175153
static inline bool is_leap_year(uint32_t year)
176154
{
177155
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
@@ -785,11 +763,9 @@ void log_output_dropped_process(const struct log_output *output, uint32_t cnt)
785763
cnt = MIN(cnt, 9999);
786764
len = snprintk(buf, sizeof(buf), "%d", cnt);
787765

788-
buffer_write(outf, (uint8_t *)prefix, sizeof(prefix) - 1,
789-
output->control_block->ctx);
790-
buffer_write(outf, buf, len, output->control_block->ctx);
791-
buffer_write(outf, (uint8_t *)postfix, sizeof(postfix) - 1,
792-
output->control_block->ctx);
766+
log_output_write(outf, (uint8_t *)prefix, sizeof(prefix) - 1, output->control_block->ctx);
767+
log_output_write(outf, buf, len, output->control_block->ctx);
768+
log_output_write(outf, (uint8_t *)postfix, sizeof(postfix) - 1, output->control_block->ctx);
793769
}
794770

795771
void log_output_timestamp_freq_set(uint32_t frequency)

subsys/logging/log_output_dict.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
#include <zephyr/sys/__assert.h>
1313
#include <zephyr/sys/util.h>
1414

15-
static void buffer_write(log_output_func_t outf, uint8_t *buf, size_t len,
16-
void *ctx)
17-
{
18-
int processed;
19-
20-
do {
21-
processed = outf(buf, len, ctx);
22-
len -= processed;
23-
buf += processed;
24-
} while (len != 0);
25-
}
26-
2715
void log_dict_output_msg_process(const struct log_output *output,
2816
struct log_msg *msg, uint32_t flags)
2917
{
@@ -40,19 +28,19 @@ void log_dict_output_msg_process(const struct log_output *output,
4028

4129
output_hdr.source = (source != NULL) ? log_source_id(source) : 0U;
4230

43-
buffer_write(output->func, (uint8_t *)&output_hdr, sizeof(output_hdr),
44-
(void *)output->control_block->ctx);
31+
log_output_write(output->func, (uint8_t *)&output_hdr, sizeof(output_hdr),
32+
(void *)output->control_block->ctx);
4533

4634
size_t len;
4735
uint8_t *data = log_msg_get_package(msg, &len);
4836

4937
if (len > 0U) {
50-
buffer_write(output->func, data, len, (void *)output->control_block->ctx);
38+
log_output_write(output->func, data, len, (void *)output->control_block->ctx);
5139
}
5240

5341
data = log_msg_get_data(msg, &len);
5442
if (len > 0U) {
55-
buffer_write(output->func, data, len, (void *)output->control_block->ctx);
43+
log_output_write(output->func, data, len, (void *)output->control_block->ctx);
5644
}
5745

5846
log_output_flush(output);
@@ -65,6 +53,6 @@ void log_dict_output_dropped_process(const struct log_output *output, uint32_t c
6553
msg.type = MSG_DROPPED_MSG;
6654
msg.num_dropped_messages = MIN(cnt, 9999);
6755

68-
buffer_write(output->func, (uint8_t *)&msg, sizeof(msg),
69-
(void *)output->control_block->ctx);
56+
log_output_write(output->func, (uint8_t *)&msg, sizeof(msg),
57+
(void *)output->control_block->ctx);
7058
}

0 commit comments

Comments
 (0)