Re: Logging with a string via %s


Paul Sokolovsky
 

Hello,

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

For an operating system that aims to support various functional
safety certifications, asynchronous rendering of %s is a terrible
idea.
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.

Andrew

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

Hi,
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.

Thanks,





--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog

Join devel@lists.zephyrproject.org to automatically receive all group messages.