Re: Logging with a string via %s


lairdjm
 

Hi Stefan,

Brilliant, didn’t think of that, all working now, thank you.

Thanks,

Jamie

 

From: devel@... <devel@...> On Behalf Of Stefan Jaritz via Lists.Zephyrproject.Org

Sent: 15 May 2019 12:27
To: devel@...
Cc: devel@...
Subject: Re: [Zephyr-devel] Logging with a string via %s

 

EXTERNAL EMAIL: Be careful with attachments and links.

Hey Lairdjm,

 

Depending on you logging setup, the log of the string is done inside the "               LOG_DBG" command or later.

Later means, that your main function was already left and your local variables are gone = invalid.

Try to add following lines at your proj.conf:

CONFIG_LOG=y
# CONFIG_LOG_PROCESS_THREAD=y
# CONFIG_LOG_INPLACE_PROCESS=y
CONFIG_LOG_IMMEDIATE=y
CONFIG_LOG_BACKEND_SHOW_COLOR=y

This will force the logger "execute" the log function.

Good luck!

Stefan

 

On 15/05/2019 11:52, lairdjm wrote:

Hi,

I’m seeing an issue whereby I am unable to log strings using LOG_DBG() and %s format, for a quick example I modified the hello world sample to enable logging and change the code to this:

#define LOG_DOMAIN test_domain

#include <logging/log.h>

LOG_MODULE_REGISTER(LOG_DOMAIN);

 

void main(void)

{

                char baTmpBuf[12];

                sprintf(baTmpBuf, "ffffffff");

                LOG_DBG("Test : %s", baTmpBuf);

 

                printk("Hello World! %s\n", CONFIG_BOARD);

}

I expect to see “Test : ffffffff” but instead I am getting “Test : %*”, if I change the code to inefficiently log each character, e.g.:

                LOG_DBG("Test : %c%c%c%c%c%c%c%c", baTmpBuf[0], baTmpBuf[1], baTmpBuf[2], baTmpBuf[3], baTmpBuf[4], baTmpBuf[5], baTmpBuf[6], baTmpBuf[7]);

Then I get the expected output: “Test : ffffffff”

 

So why is %s not outputting a string? If there a configuration option I have missed? I have tried toggling “Format strings with libc” option but it doesn’t change anything. I’m testing on an nRF52840 using the nrf52840_pca10056 board file.

Thanks,
Jamie

THIS MESSAGE, ANY ATTACHMENT(S), AND THE INFORMATION CONTAINED HEREIN MAY BE PROPRIETARY TO LAIRD CONNECTIVITY, INC. AND/OR ANOTHER PARTY, AND MAY FURTHER BE INTENDED TO BE KEPT CONFIDENTIAL. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE DELETE THE EMAIL AND ANY ATTACHMENTS, AND IMMEDIATELY NOTIFY THE SENDER BY RETURN EMAIL. THIS MESSAGE AND ITS CONTENTS ARE THE PROPERTY OF LAIRD CONNECTIVITY, INC. AND MAY NOT BE REPRODUCED OR USED WITHOUT THE EXPRESS WRITTEN CONSENT OF LAIRD CONNECTIVITY, INC.

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