logging: Add an option for a custom log header

There are scenarios when it is necessary to globally redefine
a log macro. The existing logging frontend is not sufficient since
it redirects at the function level.

One example is using pigweed_tokenzier. The pigweed tokenizer depends
on intercepting log strings at the macro level to function.

Introduce an option to include a custom application provided header
named "zephyr_custom_log.h" at the end of log.h. This allows an
application to extend the LOG_* macros globally.

This change includes a simple test that redefines the core LOG macros
to include a custom prefix.

Signed-off-by: Rob Barnes <robbarnes@google.com>
This commit is contained in:
Rob Barnes 2022-12-14 08:11:17 -07:00 committed by Carles Cufí
commit 61b5566e74
8 changed files with 163 additions and 1 deletions

View file

@ -43,7 +43,8 @@ config LOG_FRONTEND
bool "Frontend"
help
When enabled, logs are redirected to a custom frontend which is the
fastest way of getting logs out.
fastest way of getting logs out. The logs are redirected at the function
level. To redirect logs at the macro level, see LOG_CUSTOM_HEADER.
config LOG_FRONTEND_ONLY
bool "No backends"
@ -52,6 +53,14 @@ config LOG_FRONTEND_ONLY
Option indicates that there are no backends intended to be used.
Code asserts if any backend is enabled.
config LOG_CUSTOM_HEADER
bool "Include Custom Log Header"
help
When enabled, a custom application provided header, named
"zephyr_custom_log.h", is included at the end of log.h. This enables
extension of the LOG_* APIs at the macro level. Please use cautiously!
The internal LOG API may change in future releases.
config LOG_DEFAULT_MINIMAL
bool