From 2f6370c0dd4ffdc1212a3aaa64f5646d477dd6c8 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Fri, 14 Sep 2018 09:16:52 +0200 Subject: [PATCH] subsys: logging: for native_posix use appropriate tracing For the native_posix backend, use the appropiate tracing functions and enable color if it should be Signed-off-by: Alberto Escolar Piedras --- subsys/logging/log_backend_native_posix.c | 40 ++++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) 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;