This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF_LOG_INFO can't print a string.

Hello,

The following code was embedded in main function, the sdk version is 15.2.

NRF_LOG_INFO("test begin: ");

char string[] = "This is a string.";
NRF_LOG_INFO(string);

NRF_LOG_INFO("This is a string, too.");

NRF_LOG_INFO("test end ");

the debug console show as below:

My question is , why string "This is a string" can't print out?

Thank you!

Parents
  • The reason is because NRF_LOG_XXX uses many macro definitions that assumes that the args of the NRF_LOG are similar to printf. It uses __VA_ARGS__ and hence what you are trying to do does not make sense to the macro expansion of the NRF_LOG_INFO.

    To achieve what you want you should use a format indicator as below.

    NRF_LOG_INFO("test begin: ");
    
    static char string[] = "This is a string.";
    NRF_LOG_INFO("%s", string);
    
    NRF_LOG_INFO("This is a string, too.");
    
    NRF_LOG_INFO("test end");

    You will get what you need then

Reply
  • The reason is because NRF_LOG_XXX uses many macro definitions that assumes that the args of the NRF_LOG are similar to printf. It uses __VA_ARGS__ and hence what you are trying to do does not make sense to the macro expansion of the NRF_LOG_INFO.

    To achieve what you want you should use a format indicator as below.

    NRF_LOG_INFO("test begin: ");
    
    static char string[] = "This is a string.";
    NRF_LOG_INFO("%s", string);
    
    NRF_LOG_INFO("This is a string, too.");
    
    NRF_LOG_INFO("test end");

    You will get what you need then

Children
No Data
Related