zephyr/subsys/logging/log_minimal.c
Andrew Boie 7e29c9da0b logging: add minimal implementation
The log mechanism, even in immediate mode, adds somewhere
between 1K-2K of footprint to applications that use it.

We want to standardize the logging APIs for all logging
within the kernel, but need to not let platforms with
very constrained RAM/ROM in the dust.

This patch introduces CONFIG_LOG_MINIMAL, which is a very
thin wrapper to printk(). It supports the APIs expressed
in logging/log.h.

This will be the new default for test cases.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-01 09:24:02 -04:00

51 lines
931 B
C

/*
* Copyright (c) 2019 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/printk.h>
#include <ctype.h>
#include <logging/log.h>
#define HEXDUMP_BYTES_IN_LINE 8
static void minimal_hexdump_line_print(const char *data, size_t length)
{
for (int i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) {
if (i < length) {
printk("%02x ", data[i] & 0xFF);
} else {
printk(" ");
}
}
printk("|");
for (int i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) {
if (i < length) {
char c = data[i];
printk("%c", isprint((int)c) ? c : '.');
} else {
printk(" ");
}
}
printk("\n");
}
void log_minimal_hexdump_print(int level, const char *data, size_t size)
{
while (size > 0) {
printk("%c: ", z_log_minimal_level_to_char(level));
minimal_hexdump_line_print(data, size);
if (size < HEXDUMP_BYTES_IN_LINE) {
break;
}
size -= HEXDUMP_BYTES_IN_LINE;
data += HEXDUMP_BYTES_IN_LINE;
}
}