Wirepas SDK
debug_log.h File Reference

Detailed Description

Helper file to print debug logs.

Definition in file debug_log.h.

Go to the source code of this file.

Macros

#define Print_Log(fmt, ...)
 
#define LOG_INIT()
 
#define DEBUG_LOG_MAX_LEVEL   LVL_ERROR
 
#define LVL_DEBUG   4
 Macros to define several log levels: Debug, Info, Warning, Error. More...
 
#define LVL_INFO   3
 
#define LVL_WARNING   2
 
#define LVL_ERROR   1
 
#define LVL_NOLOG   0
 
#define LVL_STRING_4   "D"
 
#define LVL_STRING_3   "I"
 
#define LVL_STRING_2   "W"
 
#define LVL_STRING_1   "E"
 
#define LVL_STRING_0   ""
 
#define DEBUG_LVL_TO_STRING(level)   LVL_STRING_##level
 Macro to retrieve a string from the log level. More...
 
#define FLUSH_DELAY_MS   45
 
#define DEBUG_LOG_PRINT_MODULE_NAME
 
#define DEBUG_LOG_PRINT_TIME
 
#define DEBUG_LOG_PRINT_LEVEL
 
#define S_MOD_NAME_PREFIX   "["DEBUG_LOG_MODULE_NAME"]"
 
#define S_TIME_PREFIX   "[%09u]"
 
#define S_TIME_SUFFIX   , lib_time->getTimestampCoarse()
 
#define S_LEVEL_PREFIX(level)   " "DEBUG_LVL_TO_STRING(level)": "
 
#define S_FUNCTION_PREFIX
 
#define S_FUNCTION_SUFFIX
 
#define S_LINE_PREFIX
 
#define S_LINE_SUFFIX
 
#define LOG(level, fmt, ...)
 Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL. More...
 
#define LOGE(fmt, ...)   LOG(LVL_ERROR, fmt __VA_OPT__(,) __VA_ARGS__)
 Set of macros that avoid to pass the full log level. More...
 
#define LOGW(fmt, ...)   LOG(LVL_WARNING, fmt __VA_OPT__(,) __VA_ARGS__)
 
#define LOGI(fmt, ...)   LOG(LVL_DEBUG, fmt __VA_OPT__(,) __VA_ARGS__)
 
#define LOGD(fmt, ...)   LOG(LVL_INFO, fmt __VA_OPT__(,) __VA_ARGS__)
 
#define LOG_BUFFER(level, buffer, size)
 Print a buffer if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL. More...
 
#define LOG_FLUSH(level)
 Actively wait that Uart buffer as been sent. More...
 

Macro Definition Documentation

◆ DEBUG_LOG_MAX_LEVEL

#define DEBUG_LOG_MAX_LEVEL   LVL_ERROR

Only logs with a level lower or equal to DEBUG_LOG_MAX_LEVEL will be printed

Note
this constant can be defined in each file including this file

Definition at line 76 of file debug_log.h.

◆ DEBUG_LOG_PRINT_LEVEL

#define DEBUG_LOG_PRINT_LEVEL

Definition at line 115 of file debug_log.h.

◆ DEBUG_LOG_PRINT_MODULE_NAME

#define DEBUG_LOG_PRINT_MODULE_NAME

Definition at line 113 of file debug_log.h.

◆ DEBUG_LOG_PRINT_TIME

#define DEBUG_LOG_PRINT_TIME

Definition at line 114 of file debug_log.h.

◆ DEBUG_LVL_TO_STRING

#define DEBUG_LVL_TO_STRING (   level)    LVL_STRING_##level

Macro to retrieve a string from the log level.

Definition at line 100 of file debug_log.h.

◆ FLUSH_DELAY_MS

#define FLUSH_DELAY_MS   45

Time to flush Usart buffer in ms (buffer is 512 bytes, so ~45ms to flush full buffer).

Definition at line 105 of file debug_log.h.

◆ LOG

#define LOG (   level,
  fmt,
  ... 
)
Value:
{ \
((uint8_t) level) <= ((uint8_t) DEBUG_LOG_MAX_LEVEL) ? \
Print_Log( \
, ##__VA_ARGS__) : \
(void)NULL; \
}

Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.

Parameters
levelSeverity of the log.
fmtFormat of the log
...The list of parameters
Examples
aes/app.c, appconfig/app.c, custom_app/app.c, scheduler/app.c, shared_data/app.c, and tinycbor/app.c.

Definition at line 173 of file debug_log.h.

◆ LOG_BUFFER

#define LOG_BUFFER (   level,
  buffer,
  size 
)
Value:
{ \
if(((uint8_t) level) <= ((uint8_t) DEBUG_LOG_MAX_LEVEL)) { \
for (uint16_t i = 0; i < size; i++) \
{ \
Print_Log("%02X ", buffer[i]); \
if ((i & 0xF) == 0xF && i != (uint8_t)(size-1)) \
{ \
Print_Log("\n"); \
} \
} \
Print_Log("\n"); \
} \
}

Print a buffer if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.

Parameters
levelSeverity of the log.
bufferPointer to the buffer to print.
sizeSize in bytes of the buffer.
Examples
aes/app.c, and tinycbor/app.c.

Definition at line 206 of file debug_log.h.

◆ LOG_FLUSH

#define LOG_FLUSH (   level)
Value:
{ \
if(((uint8_t) level) <= ((uint8_t) DEBUG_LOG_MAX_LEVEL)) { \
app_lib_time_timestamp_hp_t end; \
end = lib_time->addUsToHpTimestamp(lib_time->getTimestampHp(), \
FLUSH_DELAY_MS * 1000); \
while (lib_time->isHpTimestampBefore(lib_time->getTimestampHp(),end)); \
} \
}

Actively wait that Uart buffer as been sent.

Parameters
levelOnly wait if level is lower or equal to DEBUG_LOG_MAX_LEVEL.
Examples
tinycbor/app.c.

Definition at line 226 of file debug_log.h.

◆ LOG_INIT

#define LOG_INIT ( )

◆ LOGD

#define LOGD (   fmt,
  ... 
)    LOG(LVL_INFO, fmt __VA_OPT__(,) __VA_ARGS__)

Definition at line 194 of file debug_log.h.

◆ LOGE

#define LOGE (   fmt,
  ... 
)    LOG(LVL_ERROR, fmt __VA_OPT__(,) __VA_ARGS__)

Set of macros that avoid to pass the full log level.

Parameters
fmtFormat of the log
...The list of parameters

Definition at line 191 of file debug_log.h.

◆ LOGI

#define LOGI (   fmt,
  ... 
)    LOG(LVL_DEBUG, fmt __VA_OPT__(,) __VA_ARGS__)

Definition at line 193 of file debug_log.h.

◆ LOGW

#define LOGW (   fmt,
  ... 
)    LOG(LVL_WARNING, fmt __VA_OPT__(,) __VA_ARGS__)

Definition at line 192 of file debug_log.h.

◆ LVL_DEBUG

#define LVL_DEBUG   4

Macros to define several log levels: Debug, Info, Warning, Error.

Examples
appconfig/app.c.

Definition at line 82 of file debug_log.h.

◆ LVL_ERROR

#define LVL_ERROR   1
Examples
aes/app.c, appconfig/app.c, and tinycbor/app.c.

Definition at line 85 of file debug_log.h.

◆ LVL_INFO

#define LVL_INFO   3

◆ LVL_NOLOG

#define LVL_NOLOG   0

Definition at line 86 of file debug_log.h.

◆ LVL_STRING_0

#define LVL_STRING_0   ""

Definition at line 95 of file debug_log.h.

◆ LVL_STRING_1

#define LVL_STRING_1   "E"

Definition at line 94 of file debug_log.h.

◆ LVL_STRING_2

#define LVL_STRING_2   "W"

Definition at line 93 of file debug_log.h.

◆ LVL_STRING_3

#define LVL_STRING_3   "I"

Definition at line 92 of file debug_log.h.

◆ LVL_STRING_4

#define LVL_STRING_4   "D"

Definition at line 91 of file debug_log.h.

◆ LVL_WARNING

#define LVL_WARNING   2
Examples
tinycbor/app.c.

Definition at line 84 of file debug_log.h.

◆ Print_Log

#define Print_Log (   fmt,
  ... 
)

Simple library to print only relevant log messages.

APP_PRINTING=yes must be defined in the makefile of the application.

Add the following lines in each file using debug logs :

#define DEBUG_LOG_MODULE_NAME "module_name"
#define DEBUG_LOG_MAX_LEVEL LVL_INFO
#include "debug_log.h"

By default Module name; TimeStamp (coarse) and Debug level are printed.

By defining DEBUG_LOG_CUSTOM in the app makefile it is possible to select which debug field is printed.

Define one of the folling in the general makefile or before including "debug_log.h" to enable the corresponding field in the log message :

  • DEBUG_LOG_PRINT_MODULE_NAME
  • DEBUG_LOG_PRINT_TIME
  • DEBUG_LOG_PRINT_TIME_HP (DEBUG_LOG_PRINT_TIME and DEBUG_LOG_PRINT_TIME_HP are mutually exclusive).
  • DEBUG_LOG_PRINT_LEVEL
  • DEBUG_LOG_PRINT_FUNCTION
  • DEBUG_LOG_PRINT_LINE

Usage :

LOG(LVL_DEBUG, "This is a debug message not printed"\
"with current DEBUG_LOG_MAX_LEVEL = LVL_INFO);
LOG(LVL_INFO, "This is an info message printed"\
"with current DEBUG_LOG_MAX_LEVEL = LVL_INFO);

Definition at line 65 of file debug_log.h.

◆ S_FUNCTION_PREFIX

#define S_FUNCTION_PREFIX

Definition at line 151 of file debug_log.h.

◆ S_FUNCTION_SUFFIX

#define S_FUNCTION_SUFFIX

Definition at line 152 of file debug_log.h.

◆ S_LEVEL_PREFIX

#define S_LEVEL_PREFIX (   level)    " "DEBUG_LVL_TO_STRING(level)": "

Definition at line 142 of file debug_log.h.

◆ S_LINE_PREFIX

#define S_LINE_PREFIX

Definition at line 159 of file debug_log.h.

◆ S_LINE_SUFFIX

#define S_LINE_SUFFIX

Definition at line 160 of file debug_log.h.

◆ S_MOD_NAME_PREFIX

#define S_MOD_NAME_PREFIX   "["DEBUG_LOG_MODULE_NAME"]"

Definition at line 122 of file debug_log.h.

◆ S_TIME_PREFIX

#define S_TIME_PREFIX   "[%09u]"

Definition at line 134 of file debug_log.h.

◆ S_TIME_SUFFIX

#define S_TIME_SUFFIX   , lib_time->getTimestampCoarse()

Definition at line 135 of file debug_log.h.

LVL_INFO
#define LVL_INFO
Definition: debug_log.h:83
S_MOD_NAME_PREFIX
#define S_MOD_NAME_PREFIX
Definition: debug_log.h:122
S_TIME_SUFFIX
#define S_TIME_SUFFIX
Definition: debug_log.h:135
S_LINE_SUFFIX
#define S_LINE_SUFFIX
Definition: debug_log.h:160
S_LEVEL_PREFIX
#define S_LEVEL_PREFIX(level)
Definition: debug_log.h:142
DEBUG_LOG_MAX_LEVEL
#define DEBUG_LOG_MAX_LEVEL
Definition: debug_log.h:76
S_FUNCTION_PREFIX
#define S_FUNCTION_PREFIX
Definition: debug_log.h:151
LVL_DEBUG
#define LVL_DEBUG
Macros to define several log levels: Debug, Info, Warning, Error.
Definition: debug_log.h:82
LOG_INIT
#define LOG_INIT()
Definition: debug_log.h:66
S_FUNCTION_SUFFIX
#define S_FUNCTION_SUFFIX
Definition: debug_log.h:152
LOG
#define LOG(level, fmt,...)
Print a log message if its severity is lower or equal to DEBUG_LOG_MAX_LEVEL.
Definition: debug_log.h:173
S_TIME_PREFIX
#define S_TIME_PREFIX
Definition: debug_log.h:134
S_LINE_PREFIX
#define S_LINE_PREFIX
Definition: debug_log.h:159
FLUSH_DELAY_MS
#define FLUSH_DELAY_MS
Definition: debug_log.h:105