Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF_LOG_DEBUG with dynamic string

Hello,

# Issue
I'm using a wrapper function for logging, in which you can set callbacks, which get passed the format string, and the va_list of arguments.

I'd like to use as one of my callbacks, the NRF_LOG_XXX functions.
I however notice that they do not accept va_lists.
In order to get around that, I pre-processed the format string and va_list with vsprintf, and then I attempted to pass that string to NRF_LOG_DEBUG.

Here's a little snippet to show what I mean

char formatted_log[1024];

vsnprintf(formatted_log, 1024, fmt, ap);
NRF_LOG_RAW_INFO(formatted_log)

However it ended in an infinite loop, or a HardFault.
I suspect the issue is that NRF_LOG_XXX cannot have a variable string as the first argument, is this correct?


# Workaround
As a work around, one can, as well as the vsprintf, use "%s" as the format string, and have your created format string as an argument.

Thanks,
Joshua

Related