diff --git a/subsys/logging/log_backend_native_posix.c b/subsys/logging/log_backend_native_posix.c index 24487d2b0f4..258bae9ebdd 100644 --- a/subsys/logging/log_backend_native_posix.c +++ b/subsys/logging/log_backend_native_posix.c @@ -6,20 +6,50 @@ */ #include - +#include +#include #include #include #include #include -#include -#include +#include "posix_trace.h" -static u8_t buf[2048]; +#define _STDOUT_BUF_SIZE 256 +static char stdout_buff[_STDOUT_BUF_SIZE]; +static int n_pend; /* Number of pending characters in buffer */ + +static void preprint_char(int c) +{ + int printnow = 0; + + if (c == '\r') { + /* Discard carriage returns */ + return; + } + if (c != '\n') { + stdout_buff[n_pend++] = c; + stdout_buff[n_pend] = 0; + } else { + printnow = 1; + } + + if (n_pend >= _STDOUT_BUF_SIZE - 1) { + printnow = 1; + } + + if (printnow) { + posix_print_trace("%s\n", stdout_buff); + n_pend = 0; + stdout_buff[0] = 0; + } +} + +static u8_t buf[_STDOUT_BUF_SIZE]; int char_out(u8_t *data, size_t length, void *ctx) { for (size_t i = 0; i < length; i++) { - putchar(data[i]); + preprint_char(data[i]); } return length;