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>
This commit is contained in:
Andrew Boie 2019-09-22 16:44:43 -07:00 committed by Anas Nashif
commit 7e29c9da0b
7 changed files with 222 additions and 94 deletions

View file

@ -28,12 +28,6 @@ extern "C" {
* @{
*/
#define LOG_LEVEL_NONE 0
#define LOG_LEVEL_ERR 1
#define LOG_LEVEL_WRN 2
#define LOG_LEVEL_INF 3
#define LOG_LEVEL_DBG 4
/**
* @brief Writes an ERROR level message to the log.
*
@ -247,6 +241,7 @@ extern "C" {
#define LOG_INST_HEXDUMP_DBG(_log_inst, _data, _length, _str) \
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_DBG, _log_inst, _data, _length, _str)
#ifndef CONFIG_LOG_MINIMAL
/**
* @brief Writes an formatted string to the log.
*
@ -266,13 +261,29 @@ void log_printk(const char *fmt, va_list ap);
* Logger allocates a buffer and copies input string returning a pointer to the
* copy. Logger ensures that buffer is freed when logger message is freed.
*
* Depending on configuration, this function may do nothing and just pass
* along the supplied string pointer. Do not rely on this function to always
* make a copy!
*
* @param str Transient string.
*
* @return Copy of the string or default string if buffer could not be
* allocated. String may be truncated if input string does not fit in
* a buffer from the pool (see CONFIG_LOG_STRDUP_MAX_STRING).
* a buffer from the pool (see CONFIG_LOG_STRDUP_MAX_STRING). In
* some configurations, the original string pointer is returned.
*/
char *log_strdup(const char *str);
#else
static inline void log_printk(const char *fmt, va_list ap)
{
vprintk(fmt, ap);
}
static inline char *log_strdup(const char *str)
{
return (char *)str;
}
#endif /* CONFIG_LOG_MINIMAL */
#ifdef __cplusplus
}