logging: Handle dropped messages in log_output

Extended log_output interface to handle dropped
messages. Log_output is printing a message containing
number of dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2018-12-14 10:47:13 +01:00 committed by Carles Cufí
commit a7568e4a6a
2 changed files with 48 additions and 15 deletions

View file

@ -98,6 +98,15 @@ void log_output_msg_process(const struct log_output *log_output,
struct log_msg *msg, struct log_msg *msg,
u32_t flags); u32_t flags);
/** @brief Process dropped messages indication.
*
* Function prints error message indicating lost log messages.
*
* @param log_output Pointer to the log output instance.
* @param cnt Number of dropped messages.
*/
void log_output_dropped_process(const struct log_output *log_output, u32_t cnt);
/** @brief Flush output buffer. /** @brief Flush output buffer.
* *
* @param log_output Pointer to the log output instance. * @param log_output Pointer to the log output instance.

View file

@ -10,18 +10,19 @@
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#include <stdio.h>
#define LOG_COLOR_CODE_DEFAULT "\x1B[0m"
#define LOG_COLOR_CODE_RED "\x1B[1;31m"
#define LOG_COLOR_CODE_YELLOW "\x1B[1;33m"
#define HEXDUMP_BYTES_IN_LINE 8 #define HEXDUMP_BYTES_IN_LINE 8
#define LOG_COLOR_CODE_DEFAULT "\x1B[0m" #define DROPPED_COLOR_PREFIX \
#define LOG_COLOR_CODE_BLACK "\x1B[1;30m" _LOG_EVAL(CONFIG_LOG_BACKEND_SHOW_COLOR, (LOG_COLOR_CODE_RED), ())
#define LOG_COLOR_CODE_RED "\x1B[1;31m"
#define LOG_COLOR_CODE_GREEN "\x1B[1;32m" #define DROPPED_COLOR_POSTFIX \
#define LOG_COLOR_CODE_YELLOW "\x1B[1;33m" _LOG_EVAL(CONFIG_LOG_BACKEND_SHOW_COLOR, (LOG_COLOR_CODE_DEFAULT), ())
#define LOG_COLOR_CODE_BLUE "\x1B[1;34m"
#define LOG_COLOR_CODE_MAGENTA "\x1B[1;35m"
#define LOG_COLOR_CODE_CYAN "\x1B[1;36m"
#define LOG_COLOR_CODE_WHITE "\x1B[1;37m"
static const char *const severity[] = { static const char *const severity[] = {
NULL, NULL,
@ -114,18 +115,23 @@ static int print_formatted(const struct log_output *log_output,
return length; return length;
} }
void log_output_flush(const struct log_output *log_output) static void buffer_write(log_output_func_t outf, u8_t *buf, size_t len,
void *ctx)
{ {
int offset = 0;
int len = log_output->control_block->offset;
int processed; int processed;
do { do {
processed = log_output->func(&log_output->buf[offset], len, processed = outf(buf, len, ctx);
log_output->control_block->ctx);
len -= processed; len -= processed;
offset += processed; buf += processed;
} while (len); } while (len);
}
void log_output_flush(const struct log_output *log_output)
{
buffer_write(log_output->func, log_output->buf,
log_output->control_block->offset,
log_output->control_block->ctx);
log_output->control_block->offset = 0; log_output->control_block->offset = 0;
} }
@ -524,6 +530,24 @@ void log_output_msg_process(const struct log_output *log_output,
log_output_flush(log_output); log_output_flush(log_output);
} }
void log_output_dropped_process(const struct log_output *log_output, u32_t cnt)
{
char buf[5];
int len;
static const char prefix[] = DROPPED_COLOR_PREFIX "--- ";
static const char postfix[] =
" messages dropped ---\r\n" DROPPED_COLOR_POSTFIX;
log_output_func_t outf = log_output->func;
struct device *dev = (struct device *)log_output->control_block->ctx;
cnt = min(cnt, 9999);
len = snprintf(buf, sizeof(buf), "%d", cnt);
buffer_write(outf, (u8_t *)prefix, sizeof(prefix) - 1, dev);
buffer_write(outf, buf, len, dev);
buffer_write(outf, (u8_t *)postfix, sizeof(postfix) - 1, dev);
}
void log_output_timestamp_freq_set(u32_t frequency) void log_output_timestamp_freq_set(u32_t frequency)
{ {
timestamp_div = 1U; timestamp_div = 1U;