Introduction

NRF_LOG macros are used for printing logs on screen from Smablo Cpu Shield. The log are helpfull when debugging project and printing interresting values and logs for us. The nrf macors are avaibale after including nrf_log.h library to your project.

Getting started

To get started with NRF_LOG you will need :

Take Smablo development board from your Smablo Development kit and place CPU on the described connector like in the pictures and video below:

{.force-inline} {.force-inline}

When you’ve done connecting Shield you can connect Smablo Development board to your computer with USB cable.

Most common macros

NRF_LOG_INFO

Macro for logging information messages. It prints formatted string with prefix or timestamp with up to seven arguments. For example to print a simple string:

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_INFO("test string \n\r");

}

or to print a number:

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_INFO("print number  %d  \n\r", 2);

}

NRF_LOG_RAW_INFO

This is similar to NRF_LOG_INFO macro that print strings without any prefix or timestamp.

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_RAW_INFO("print number  %d  \n\r", 2);

}

NRF_LOG_DEBUG

Macro for logging debug messages. It prints formatted string with prefix or timestamp with up to seven arguments. For example to print a simple string:

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_DEBUG("This is a debug log \r\n");

}

NRF_LOG_ERROR

Macro for logging error messages. It prints formatted string with prefix or timestamp with up to seven arguments. The error message is also colored red. For example to print a simple string:

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_ERROR("This is an error \r\n");

}
![](logcombined.png?cropResize=800 "NRF_LOG_ERROR red color")

NRF_LOG_WARNING

Macro for logging warning messages. It prints formatted string with prefix or timestamp with up to seven arguments. The error message is also colored yellow. For example to print a simple string:

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_WARNING("This is a warning \r\n");

}

NRF_LOG_HEXDUMP_INFO

Macro for logging information raw bytes in hexadecimal format. For example to print a simple data array:

#include "nrf_log.h"

void nrf_example(void)
{
    static uint8_t data[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};

    NRF_LOG_HEXDUMP_INFO(data,sizeof(data));

}

NRF_LOG_HEXDUMP_DEBUG

Macro for logging debug raw bytes in hexadecimal format. For example to print a simple data array:

#include "nrf_log.h"

void nrf_example(void)
{
    static uint8_t data[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};

    NRF_LOG_HEXDUMP_DEBUG(data,sizeof(data));

}

NRF_LOG_HEXDUMP_ERROR

Macro for logging error raw bytes in hexadecimal format in red color. For example to print a simple data array:

#include "nrf_log.h"

void nrf_example(void)
{
    static uint8_t data[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};

    NRF_LOG_HEXDUMP_ERROR(data,sizeof(data));

}

NRF_LOG_HEXDUMP_WARNING

Macro for logging warning raw bytes in hexadecimal format in yellow color. For example to print a simple data array:

#include "nrf_log.h"

void nrf_example(void)
{
    static uint8_t data[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};

    NRF_LOG_HEXDUMP_ERROR(data,sizeof(data));

}

Float numbers

To log float data we can use any of log macros but we need to also NRF_LOG_FLOAT_MARKER marker that will pass the formatted number to the log and NRF_LOG_FLOAT macrov that will split the float number into two numbers (integer and residuum). You should use it just like it was shown below:

#include "nrf_log.h"

void nrf_example(void)
{

    NRF_LOG_INFO("My float number " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(-1.23));

}

nrf_log_push

Function will print up to six deferred strings

#include "nrf_log.h"

void nrf_example(void)
{

  char *str = "this is my string";
    NRF_LOG_RAW_DEBUG("%s\r\n", nrf_log_push((char*)str));

}