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

Unable to use NRF_LOG_DEBUG with CLI example

Baseline: CLI example on the 52832 with SDK v15.3

I assume the issue will be some more undocumented fix.

sdk_config.h

// <o> NRF_LOG_DEFAULT_LEVEL  - Default Severity level
 
// <0=> Off 
// <1=> Error 
// <2=> Warning 
// <3=> Info 
// <4=> Debug 

#ifndef NRF_LOG_DEFAULT_LEVEL
#define NRF_LOG_DEFAULT_LEVEL 4
#endif

main.c from the CLI example (UART backend)

NRF_LOG_INFO("This is an INFO Message");
NRF_LOG_DEBUG("This is a DEBUG Message");
NRF_LOG_WARNING("This is a WARNING Message");
NRF_LOG_ERROR("This is a ERROR Message");

Output of the program (If that is too small, the Debug statement is not printed.)

You cannot add a DEBUG color (NRF_LOG_DEBUG_COLOR) because it breaks the build due to redefinition.  However, I do not think that is the problem. 

It is tedious to go through the log code because the code is generated on the fly by 10 deep macros where symbol names are made by ## context.

Anybody have an idea what I am missing.

Thanks,

Jim

Parents
  •  I am using the CLI example right out of the box.  The only changes I made was to add my log statements.  I made the change you suggested to the nrf_cli_init() and do not see any change in behavior.  I am using your example so that I do not have to share proprietary code.   I want to be able to log 4 different levels of logs. 

    FYI I have not turned on Log support for any other modules.  I just want to see the 4 logs in my main.c for now.  Any other ideas?  Did you try my example?  SHow me you r output and attach your sdk_config.h and main.c   I can attest your suggestions do not work.

    Thank you

  • Well it did not work for me.  I do not have any more time to waste on this so I will close it unanswered.  I tried on 15.3 and 16.0 and it did not work.  I do not want to log other modules, I want to log the app/main.c.  Did you not change the nrf_cli_init for the RTT?  That is not protected by an ifdef and requires a log level.  Not sure why logging has been made so complicated, but no worries.   

  • How does one add logging to the app?  I did not see a #define for log  level for the app.  In actuality, I never see any debug log from any modules so please, i ask again, zip up your code and attach to this bug.  I will try one last time before giving up.

    main.c
    
    static void cli_init(void)
    {
        ret_code_t ret;
    
    #if CLI_OVER_USB_CDC_ACM
        ret = nrf_cli_init(&m_cli_cdc_acm, NULL, true, true, NRF_LOG_SEVERITY_INFO);
        APP_ERROR_CHECK(ret);
    #endif
    
    #if CLI_OVER_UART
        nrf_drv_uart_config_t uart_config = NRF_DRV_UART_DEFAULT_CONFIG;
        uart_config.pseltxd = TX_PIN_NUMBER;
        uart_config.pselrxd = RX_PIN_NUMBER;
        uart_config.hwfc    = NRF_UART_HWFC_DISABLED;
        ret = nrf_cli_init(&m_cli_uart, &uart_config, true, true, NRF_LOG_SEVERITY_DEBUG);
        APP_ERROR_CHECK(ret);
    #endif
    
    // WHAT ABOUT THIS CLI INIT LOG LEVEL.  I HAVE TRIED BOTH
        ret = nrf_cli_init(&m_cli_rtt, NULL, true, true, NRF_LOG_SEVERITY_INFO);
        APP_ERROR_CHECK(ret);
    }
    
    ...
    main()
    {
    
    ...
    
    cli_init();
    
        usbd_init();
    
        ret = fds_init();
        APP_ERROR_CHECK(ret);
    
    
        UNUSED_RETURN_VALUE(nrf_log_config_load());
    
        cli_start();
    
        flashlog_init();
    
        stack_guard_init();
    
        NRF_LOG_RAW_INFO("Command Line Interface example started.\n");
        NRF_LOG_RAW_INFO("Please press the Tab key to see all available commands.\n");
    
    
        NRF_LOG_INFO("This is an INFO Message");
        NRF_LOG_DEBUG("This is a DEBUG Message");
        NRF_LOG_WARNING("This is a WARNING Message");
        NRF_LOG_ERROR("This is a ERROR Message");
        
        
    sdk_config.h
    ...............................................    
        #ifndef NRF_LOG_DEFAULT_LEVEL
    #define NRF_LOG_DEFAULT_LEVEL 4
    #endif
    
    

  • As far as I know, there are no configs for setting the log level specific for the app, it will use the NRF_LOG_DEFAULT_LEVEL config and use the module name "app". There is nothing stopping you from creating your own configs for the app, and change the name of the module, similar to how this is done in other modules:

    #define MAIN_CONFIG_LOG_ENABLED 1
    #define MAIN_CONFIG_LOG_LEVEL 4
    #define MAIN_CONFIG_INFO_COLOR 2
    #define MAIN_CONFIG_DEBUG_COLOR 3
    
    #define NRF_LOG_MODULE_NAME main_cli
    #if MAIN_CONFIG_LOG_ENABLED
    #define NRF_LOG_LEVEL       MAIN_CONFIG_LOG_LEVEL
    #define NRF_LOG_INFO_COLOR  MAIN_CONFIG_INFO_COLOR
    #define NRF_LOG_DEBUG_COLOR MAIN_CONFIG_DEBUG_COLOR
    #else //MAIN_CONFIG_LOG_ENABLED
    #define NRF_LOG_LEVEL       0
    #endif //MAIN_CONFIG_LOG_ENABLED
    #include "nrf_log.h"
    NRF_LOG_MODULE_REGISTER();

    I have included the modified CLI application from SDK 16.0.0, which I used to test:

    cli_debug_sdk16.zip

  • When I build your app, I do not see the debug statements.  I am using SDK 16.0.   I guess I should have told use I was not using segger.  I am using the straight armgcc project, which was not included in your zip file, so I was forced to use my own.  My build environment is Linux so I think we have narrowed down the problem.  Not sure if the build environment affects the functionality.    Can you reproduce this cli_debug using the armgcc environment?

Reply
  • When I build your app, I do not see the debug statements.  I am using SDK 16.0.   I guess I should have told use I was not using segger.  I am using the straight armgcc project, which was not included in your zip file, so I was forced to use my own.  My build environment is Linux so I think we have narrowed down the problem.  Not sure if the build environment affects the functionality.    Can you reproduce this cli_debug using the armgcc environment?

Children
Related