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

Heinrich Schuchardt xypron.glpk at gmx.de
Sun Jan 17 08:27:57 CET 2021


On 1/14/21 4:30 AM, Simon Glass wrote:
> 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.
>
> 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); \

log() should call debug() for log_level = LOGL_DEBUG.

Best regards

Heinrich

> +	})
>   #endif
>
>   #define log_nop(_cat, _level, _fmt, _args...) ({ \
>



More information about the U-Boot mailing list