[PATCH 4/4] log: Convert log values to printf() if not enabled

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Jan 14 05:06:25 CET 2021


Am 14. Januar 2021 04:30:51 MEZ schrieb Simon Glass <sjg at chromium.org>:
>At present if logging not enabled, log_info() becomes a nop. But we
>want
>log output at the 'info' level to be akin to printf(). Update the macro
>to
>pass the output straight to printf() in this case.

Looking at 

https://github.com/trini/u-boot/blob/master/include/log.h#L172

the commit message seems not to precisely describe in which cases printf() was not called.

We have a nolog unit test. Should that test be extended?

https://github.com/trini/u-boot/blob/master/test/log/nolog_test.c

For the naked log() is see the difference.

Is this patch fixing a recent change?

Best regards

Heinrich


>
>Signed-off-by: Simon Glass <sjg at chromium.org>
>---
>
> doc/develop/logging.rst |  5 +++--
> include/log.h           | 12 ++++++++----
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
>diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst
>index b6c6b45049f..fdc869204df 100644
>--- a/doc/develop/logging.rst
>+++ b/doc/develop/logging.rst
>@@ -54,6 +54,9 @@ If CONFIG_LOG is not set, then no logging will be
>available.
>The above have SPL and TPL versions also, e.g. CONFIG_SPL_LOG_MAX_LEVEL
>and
> CONFIG_TPL_LOG_MAX_LEVEL.
> 
>+If logging is disabled, the default behaviour is to output any message
>at
>+level LOGL_INFO and below.
>+
> Temporary logging within a single file
> --------------------------------------
> 
>@@ -293,8 +296,6 @@ More logging destinations:
> 
> Convert debug() statements in the code to log() statements
> 
>-Support making printf() emit log statements at L_INFO level
>-
> Convert error() statements in the code to log() statements
> 
> Figure out what to do with BUG(), BUG_ON() and warn_non_spl()
>diff --git a/include/log.h b/include/log.h
>index c5c1cf92356..3d19f0448da 100644
>--- a/include/log.h
>+++ b/include/log.h
>@@ -175,25 +175,29 @@ static inline int _log_nop(enum log_category_t
>cat, enum log_level_t level,
> #define log_io(_fmt...)		log_nop(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt)
> #endif
> 
>-#if CONFIG_IS_ENABLED(LOG)
> #ifdef LOG_DEBUG
> #define _LOG_DEBUG	LOGL_FORCE_DEBUG
> #else
> #define _LOG_DEBUG	0
> #endif
> 
>+#if CONFIG_IS_ENABLED(LOG)
>+
> /* Emit a log record if the level is less that the maximum */
> #define log(_cat, _level, _fmt, _args...) ({ \
> 	int _l = _level; \
>-	if (CONFIG_IS_ENABLED(LOG) && \
>-	    (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL)) \
>+	if ((_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL)) \
> 		_log((enum log_category_t)(_cat), \
> 		     (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \
> 		     __LINE__, __func__, \
> 		      pr_fmt(_fmt), ##_args); \
> 	})
> #else
>-#define log(_cat, _level, _fmt, _args...)
>+#define log(_cat, _level, _fmt, _args...) ({ \
>+	int _l = _level; \
>+	if ((_LOG_DEBUG != 0 || _l <= LOGL_INFO)) \
>+		printf(_fmt, ##_args); \
>+	})
> #endif
> 
> #define log_nop(_cat, _level, _fmt, _args...) ({ \



More information about the U-Boot mailing list