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 <alpi@oticon.com>
This commit is contained in:
Alberto Escolar Piedras 2018-09-14 09:16:52 +02:00 committed by Carles Cufí
parent eca0fb6ca0
commit 2f6370c0dd
1 changed files with 35 additions and 5 deletions

View File

@ -6,20 +6,50 @@
*/
#include <stdio.h>
#include <stddef.h>
#include <logging/log_backend.h>
#include <logging/log_backend_native_posix.h>
#include <logging/log_core.h>
#include <logging/log_msg.h>
#include <logging/log_output.h>
#include <device.h>
#include <uart.h>
#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;