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

disable logging

I want to disable logging (which is working OK). In my app.config.h I have set the following:

#undef NRF_LOG_ENABLED
#define NRF_LOG_BACKEND_SERIAL_USES_UART 0
#define NRF_LOG_BACKEND_SERIAL_USES_RTT 1
#define NRF_LOG_DEFAULT_LEVEL 4

Now I get this during linking:

...../../../main.c:130: undefined reference to `nrf_log_frontend_std_0'
...../../../main.c:134: undefined reference to `nrf_log_frontend_std_1'

What have I forgotten please?

  • Which SDK is this? Do you mean sdk_config.h and not app.config.h?

  • Hi Ole, SDK 12_2.0.

    Perhaps I am confused about the purpose and correct usage of these two config.h files?
    (Is there a note about correct usage in the documentation somewhere?)

    I have sdk_config.h that contains this fragment:

    //==========================================================
    // <e> NRF_LOG_ENABLED - nrf_log - Logging
    //==========================================================
    #ifndef NRF_LOG_ENABLED
    #define NRF_LOG_ENABLED 0
    #endif
    #if  NRF_LOG_ENABLED
    // <e> NRF_LOG_USES_COLORS ... etc
    

    I am compiling with the C flag -DUSE_APP_CONFIG and I have an app_config.h with these settings:

    #undef NRF_LOG_ENABLED
    #define NRF_LOG_BACKEND_SERIAL_USES_UART 0
    #define NRF_LOG_BACKEND_SERIAL_USES_RTT 1
    #define NRF_LOG_DEFAULT_LEVEL 4
    #define NRF_LOG_DEFERRED 0
    #define NRF_LOG_BACKEND_MAX_STRING_LENGTH 128
    #define NRF_LOG_USES_TIMESTAMP 0
    #define NRF_LOG_TIMESTAMP_DIGITS  10
    #define NRF_LOG_USES_COLORS 1
    #define NRF_LOG_INFO_COLOR 0
    #define NRF_LOG_ERROR_COLOR 2
    #define NRF_LOG_DEBUG_COLOR 4
    #define NRF_LOG_WARNING_COLOR 7
    
  • Why are you undefining NRF_LOG_ENABLED? This is probably the reason why it is not working.

  • Hi Ole,

    Kind of solved.

    I thought all logging would be disabled by defining NRF_LOG_ENABLED=0. I see that this does not remove the print calls. It only seems to remove the calls to the "getchar" functionality, as follows:

    #if NRF_MODULE_ENABLED(NRF_LOG)
    #define NRF_LOG_INTERNAL_GETCHAR()  nrf_log_getchar()
    #else
    #define NRF_LOG_INTERNAL_GETCHAR()  (void)
    

    The print code appears not to be guarded by a similar conditional compile.

    Solution

    #define NRF_LOG_DEFAULT_LEVEL 0
    

    Is this the correct method for disabling logging?

  • EDIT: I see that the app_config.h is included in the top of the sdk_config file if USE_APP_CONFIG is defined, so it is safe to use this. The problem is if NRF_LOG_ENABLED is defined as 0 and NRF_LOG_DEFAULT_LEVEL is defined as something higher than 0, then you may have linker errors if you try to use NRF_LOG functions. This is a bit confusing (even I did not know how it works at first), I will see if we can improve this.


    previous answer for reference:

    You can set the level to 0, which is OFF, this will disable the logging. You can define NRF_LOG_ENABLED=0, but if you do this in another config file than sdk_config.h, then you need to make sure that this config file is always included when the sdk_config.h file is included (and also probably best if included before the sdk_config.h file). If not, you will have different defines for different files and the linker may fail or worse, the code behaves strange. For this reason I would only use one config file (sdk_config.h).

Related