Re: Logging with a string via %s

Paul Sokolovsky


On Fri, 17 May 2019 14:24:41 +0000
"Boie, Andrew P" <andrew.p.boie@...> wrote:

For an operating system that aims to support various functional
safety certifications, asynchronous rendering of %s is a terrible
Some people think that asynchronous logging, forced on unsuspecting
users, is pretty bad idea and make bets when CONFIG_LOG_IMMEDIATE will
become the default behavior again.

I think %s capability should be dropped from the logger’s format
string processing and a separate API added specifically to log a C
string, which makes an immediate copy.


From: devel@...
[mailto:devel@...] On Behalf Of
pawel.dunaj@... Sent: Friday, May 17, 2019 1:16 AM To:
devel@... Subject: Re: [Zephyr-devel] Logging
with a string via %s

To optimize time of log processing message construction is deferred.
For this reason you cannot use arrays that will not live long enough
for logger thread to see them. In other words you can always use
static arrays (like you do when calling `LOG_xyz("%s", "testme")`)
but you must never pass anything from the stack (like in your
example). You can enable `CONFIG_LOG_IMMEDIATE` but this will affect
logging performance and does not actually tells you why the problem
happened in the first place.

If you need to print array declared on stack you must call `
log_strdup()` to duplicate it.

Personally I am against this API and I indicated it will cause bugs
as people do expect `%s` to simply output a string and they also
don't read documentation for something that should just work. But at
least it makes logger faster if you look from the bright side.


Best Regards,
Paul | Open source software for ARM SoCs
Follow Linaro:!/linaroorg -

Join to automatically receive all group messages.