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

How to enable different log levels and sources?

I am working on a project on the nrf52832 board using mesh SDK v3.2.0 and SDK v15.3.  I am trying to troubleshoot an issue with the publish process for BLE mesh, but I am not able to see log messages with any levels other than LOG_LEVEL_INFO and any sources other than LOG_SRC_APP.  For instance I would like to see the log from access.c line 412. 

 __LOG(LOG_SRC_ACCESS, LOG_LEVEL_DBG1, "TX: [aop: 0x%04x] \n", p_tx_message->opcode.opcode);

I know it is likely a change in the SDK config but I am not sure which setting is the right one. Please let me know the right settings to change and the documentation location that connects the log levels and sources to the relevant settings.

Thank you


  • Hi, 

    Unfortunately, we don't have documentation regarding this on Infocenter currently. I suggest you have a look at this thread, it points out where you can find the documentation. Search for LOG_LEVEL_DEFAULT in nrf_mesh_config_core.h to change the log level. 

  • Hello,

    I would say that thread is incomplete.  However, I was able to track down why the expected logs were not printing for me.  I would like to compose a more complete answer that can be referenced for others.  There are 2 ways to get the desired LOG's to print.  The first is changing LOG_LEVEL_DEFAULT and LOG_MSK_DEFAULT in nrf_mesh_config_core.h to allow the levels and sources you want. See below.

    //lines 207 to 215 of nrf_mesh_config_core.h
    
    /** Default log level. Messages with lower criticality is filtered. */
    #ifndef LOG_LEVEL_DEFAULT
    #define LOG_LEVEL_DEFAULT LOG_LEVEL_DBG1
    #endif
    
    /** Default log mask. Messages with other sources are filtered. */
    #ifndef LOG_MSK_DEFAULT
    #define LOG_MSK_DEFAULT LOG_GROUP_STACK
    #endif

    The log level is filtered by "lower criticality" meaning a lesser value as determined by the values in log.h shown below.

    //lines 110 to 128 of log.h
    /**
     * @defgroup LOG_LEVELS Log levels
     * Defines possible criticality levels for logged messages. This can be used in
     * __LOG_INIT() to filter events by criticality.
     * @{
     */
    
    #define LOG_LEVEL_ASSERT ( 0) /**< Log level for assertions */
    #define LOG_LEVEL_ERROR  ( 1) /**< Log level for error messages. */
    #define LOG_LEVEL_WARN   ( 2) /**< Log level for warning messages. */
    #define LOG_LEVEL_REPORT ( 3) /**< Log level for report messages. */
    #define LOG_LEVEL_INFO   ( 4) /**< Log level for information messages. */
    #define LOG_LEVEL_DBG1   ( 5) /**< Log level for debug messages (debug level 1). */
    #define LOG_LEVEL_DBG2   ( 6) /**< Log level for debug messages (debug level 2). */
    #define LOG_LEVEL_DBG3   ( 7) /**< Log level for debug messages (debug level 3). */
    #define EVT_LEVEL_BASE   ( 8) /**< Base level for event logging. For internal use only. */
    #define EVT_LEVEL_ERROR  ( 9) /**< Critical error event logging level. For internal use only. */
    #define EVT_LEVEL_INFO   (10) /**< Normal event logging level. For internal use only. */
    #define EVT_LEVEL_DATA   (11) /**< Event data logging level. For internal use only. */

    The log sources are filtered LOG_MSK_DEFAULT are the sources bitwise ORed together to make LOG_GROUP_STACK from line 106 of the log.h

    //line 106 of log.h
    #define LOG_GROUP_STACK (LOG_SRC_BEARER | LOG_SRC_NETWORK | LOG_SRC_TRANSPORT)

    To alter the sources with this method add another source to the declaration of LOG_GROUP_STACK.  To change the log levels increase or decrease the LOG_LEVEL_DEFAULT using the log levels from log.h.

    The second method uses the function LOG_INIT().  If starting with example code from nordic semiconductor like the light switch example (which is what I did).  This is likely already used in the initialization function.  LOG_INIT() overrides the default values used in the first method.  The inputs and details for LOG_INIT can be found on line 245 of log.h.

    /**
     * Initializes the logging framework.
     * @param[in] msk      Log mask
     * @param[in] level    Log level
     * @param[in] callback Log callback
     */
    #define __LOG_INIT(msk, level, callback) log_init(msk, level, callback)

      "msk" is manipulated in the same way as LOG_GROUP_STACK.  "level" is manipulated the same way as LOG_LEVEL_DEFAULT.  "callback" is usually declared as LOG_CALLBACK_DEFAULT. This will allow the log to automatically initialize to the the correct publishing method if you have change between RTT and UARTE.

Related