Morse Micro IoT SDK  2.10.4
Morse Micro Logging Infrastructure

Detailed Description

Utility macros and functions for outputting log messages.

Macros

#define MM_X64_VAL(value)   ((uint32_t)(value >> 32)), ((uint32_t)value)
 Macro for printing a uint64_t as two separate uint32_t values. More...
 
#define MM_X64_FMT   "%08lx%08lx"
 Macro for format specifier to print MM_X64_VAL. More...
 
#define MM_MAC_ADDR_VAL(value)    ((value)[0]), ((value)[1]), ((value)[2]), ((value)[3]), ((value)[4]), ((value)[5])
 Macro for printing a MAC address. More...
 
#define MM_MAC_ADDR_FMT   "%02x:%02x:%02x:%02x:%02x:%02x"
 Macro for format specifier to print MM_MAC_ADDR_VAL. More...
 
#define MMLOG_LEVEL   MMLOG_LEVEL_ERR
 The selected log level. More...
 
#define MMLOG_LEVEL_INVALID   (0)
 Invalid log level. More...
 
#define MMLOG_LEVEL_OFF   (1)
 Logging disabled. More...
 
#define MMLOG_LEVEL_APP   (2)
 Special log level for always on "application" log messages. More...
 
#define MMLOG_LEVEL_ERR   (3)
 Application and error messages only. More...
 
#define MMLOG_LEVEL_WRN   (4)
 Application, error and warning messages only. More...
 
#define MMLOG_LEVEL_INF   (5)
 Application, error, warning, and info messages. More...
 
#define MMLOG_LEVEL_DBG   (6)
 Application, error, warning, info, and debug messages. More...
 
#define MMLOG_LEVEL_VRB   (7)
 Application, error, warning, info, and debug messages, plus additional verbose messages. More...
 
#define MMLOG_COLOR_RED   (31)
 ANSI color code: red. More...
 
#define MMLOG_COLOR_GREEN   (32)
 ANSI color code: green. More...
 
#define MMLOG_COLOR_ORANGE   (33)
 ANSI color code: orange. More...
 
#define MMLOG_COLOR_BLUE   (34)
 ANSI color code: blue. More...
 
#define MMLOG_COLOR_PURPLE   (35)
 ANSI color code: purple. More...
 
#define MMLOG_COLOR_CYAN   (36)
 ANSI color code: cyan. More...
 
#define MMLOG_COLOR_LIGHT_GRAY   (37)
 ANSI color code: light gray. More...
 
#define MMLOG_PREFIX_FMT   "%c %8lu %s %s[%d] "
 Log line prefix format string (log levels other than APP). More...
 
#define MMLOG_PREFIX_ARGS   lvl, mmosal_get_time_ms(), short_task_name, __func__, __LINE__
 Log line prefix arguments (log levels other than APP). More...
 
#define MMLOG_SUFFIX_FMT
 Log line suffix format string (log levels other than APP). More...
 
#define MMLOG_APP_PREFIX_FMT   " %8lu "
 Log line prefix format string (APP log level). More...
 
#define MMLOG_APP_PREFIX_ARGS   mmosal_get_time_ms()
 Log line prefix arguments (APP log level). More...
 
#define MMLOG_APP_SUFFIX_FMT
 Log line suffix format string (APP log level). More...
 
#define MMLOG_PRINTF(...)   mmosal_printf(__VA_ARGS__)
 Logging printf definition. More...
 
#define MMLOG_APP(fmt, ...)
 Display an APP level log message. More...
 
#define MMLOG(fmt, _col, _lvl, ...)
 Generic logging macro. More...
 
#define MMLOG_ERR(fmt, ...)   MMLOG(fmt, MMLOG_COLOR_RED, 'E', ##__VA_ARGS__)
 Display an ERROR level log message. More...
 
#define MMLOG_DUMP_ERR(title, buf, len)   mm_hexdump('E', __func__, __LINE__, (title), (buf), (len))
 Dump the given buffer if ERROR level logging is enabled. More...
 
#define MMLOG_WRN(fmt, ...)   printf_blackhole(fmt, ##__VA_ARGS__)
 Display an WARNING level log message. More...
 
#define MMLOG_DUMP_WRN(title, buf, len)   mm_hexdump_blackhole(title, buf, len)
 Dump the given buffer if WARNING level logging is enabled. More...
 
#define MMLOG_INF(fmt, ...)   printf_blackhole(fmt, ##__VA_ARGS__)
 Display an INFO level log message. More...
 
#define MMLOG_DUMP_INF(title, buf, len)   mm_hexdump_blackhole(title, buf, len)
 Dump the given buffer if INFO level logging is enabled. More...
 
#define MMLOG_DBG(fmt, ...)   printf_blackhole(fmt, ##__VA_ARGS__)
 Display an DEBUG level log message. More...
 
#define MMLOG_DUMP_DBG(title, buf, len)   mm_hexdump_blackhole(title, buf, len)
 Dump the given buffer if DEBUG level logging is enabled. More...
 
#define MMLOG_VRB(fmt, ...)   printf_blackhole(fmt, ##__VA_ARGS__)
 Display an VERBOSE level log message. More...
 
#define MMLOG_DUMP_VRB(title, buf, len)   mm_hexdump_blackhole(title, buf, len)
 Dump the given buffer if VERBOSE level logging is enabled. More...
 

Functions

void mm_logging_init (void)
 Initialize Morse logging API. More...
 
void mm_hexdump (char level, const char *function, unsigned line_number, const char *title, const uint8_t *buf, size_t len)
 Dumps a binary buffer in hex. More...
 
static int printf_blackhole (const char *fmt,...)
 Black hole printf to ensure arguments are referenced when a given log level is disabled. More...
 
static void mm_hexdump_blackhole (const char *title, const uint8_t *buf, size_t len)
 Black hole version of mm_hexdump() to ensure arguments are referenced when a given log level is disabled. More...
 

Macro Definition Documentation

◆ MM_MAC_ADDR_FMT

#define MM_MAC_ADDR_FMT   "%02x:%02x:%02x:%02x:%02x:%02x"

Macro for format specifier to print MM_MAC_ADDR_VAL.

Definition at line 51 of file mmlog.h.

◆ MM_MAC_ADDR_VAL

#define MM_MAC_ADDR_VAL (   value)     ((value)[0]), ((value)[1]), ((value)[2]), ((value)[3]), ((value)[4]), ((value)[5])

Macro for printing a MAC address.

This saves writing it out by hand.

Must be used in conjunction with MM_MAC_ADDR_FMT. For example:

uint8_t mac_addr[] = { 0, 1, 2, 3, 4, 5 };
printf("MAC address: " MM_MAC_ADDR_FMT "\n", MM_MAC_ADDR_VAL(mac_addr));
#define MM_MAC_ADDR_FMT
Macro for format specifier to print MM_MAC_ADDR_VAL.
Definition: mmlog.h:51
#define MM_MAC_ADDR_VAL(value)
Macro for printing a MAC address.
Definition: mmlog.h:47

Definition at line 47 of file mmlog.h.

◆ MM_X64_FMT

#define MM_X64_FMT   "%08lx%08lx"

Macro for format specifier to print MM_X64_VAL.

Definition at line 35 of file mmlog.h.

◆ MM_X64_VAL

#define MM_X64_VAL (   value)    ((uint32_t)(value >> 32)), ((uint32_t)value)

Macro for printing a uint64_t as two separate uint32_t values.

This is to allow printing of these values even when the printf implementation doesn't support it.

Definition at line 32 of file mmlog.h.

◆ MMLOG

#define MMLOG (   fmt,
  _col,
  _lvl,
  ... 
)
Value:
do { \
char lvl = (_lvl); \
char col = (_col); \
char short_task_name[3] = { '?', '?', '\0' }; \
const char *task_name = mmosal_task_name(); \
if (task_name != NULL) \
{ \
short_task_name[0] = task_name[0]; \
short_task_name[1] = task_name[1]; \
} \
(void)(lvl); \
(void)(col); \
(void)(short_task_name); \
MMLOG_PRINTF(MMLOG_PREFIX_FMT fmt MMLOG_SUFFIX_FMT, MMLOG_PREFIX_ARGS, ##__VA_ARGS__); \
} while (0)
#define MMLOG_SUFFIX_FMT
Log line suffix format string (log levels other than APP).
Definition: mmlog.h:176
#define MMLOG_PREFIX_ARGS
Log line prefix arguments (log levels other than APP).
Definition: mmlog.h:171
#define MMLOG_PREFIX_FMT
Log line prefix format string (log levels other than APP).
Definition: mmlog.h:166
const char * mmosal_task_name(void)
Get the name of the running task.

Generic logging macro.

Definition at line 248 of file mmlog.h.

◆ MMLOG_APP

#define MMLOG_APP (   fmt,
  ... 
)
Value:
##__VA_ARGS__)
#define MMLOG_APP_SUFFIX_FMT
Log line suffix format string (APP log level).
Definition: mmlog.h:194
#define MMLOG_PRINTF(...)
Logging printf definition.
Definition: mmlog.h:233
#define MMLOG_APP_PREFIX_FMT
Log line prefix format string (APP log level).
Definition: mmlog.h:184
#define MMLOG_APP_PREFIX_ARGS
Log line prefix arguments (APP log level).
Definition: mmlog.h:189

Display an APP level log message.

Definition at line 238 of file mmlog.h.

◆ MMLOG_APP_PREFIX_ARGS

#define MMLOG_APP_PREFIX_ARGS   mmosal_get_time_ms()

Log line prefix arguments (APP log level).

Definition at line 189 of file mmlog.h.

◆ MMLOG_APP_PREFIX_FMT

#define MMLOG_APP_PREFIX_FMT   " %8lu "

Log line prefix format string (APP log level).

Definition at line 184 of file mmlog.h.

◆ MMLOG_APP_SUFFIX_FMT

#define MMLOG_APP_SUFFIX_FMT

Log line suffix format string (APP log level).

Definition at line 194 of file mmlog.h.

◆ MMLOG_COLOR_BLUE

#define MMLOG_COLOR_BLUE   (34)

ANSI color code: blue.

Definition at line 119 of file mmlog.h.

◆ MMLOG_COLOR_CYAN

#define MMLOG_COLOR_CYAN   (36)

ANSI color code: cyan.

Definition at line 123 of file mmlog.h.

◆ MMLOG_COLOR_GREEN

#define MMLOG_COLOR_GREEN   (32)

ANSI color code: green.

Definition at line 115 of file mmlog.h.

◆ MMLOG_COLOR_LIGHT_GRAY

#define MMLOG_COLOR_LIGHT_GRAY   (37)

ANSI color code: light gray.

Definition at line 125 of file mmlog.h.

◆ MMLOG_COLOR_ORANGE

#define MMLOG_COLOR_ORANGE   (33)

ANSI color code: orange.

Definition at line 117 of file mmlog.h.

◆ MMLOG_COLOR_PURPLE

#define MMLOG_COLOR_PURPLE   (35)

ANSI color code: purple.

Definition at line 121 of file mmlog.h.

◆ MMLOG_COLOR_RED

#define MMLOG_COLOR_RED   (31)

ANSI color code: red.

Definition at line 113 of file mmlog.h.

◆ MMLOG_DBG

#define MMLOG_DBG (   fmt,
  ... 
)    printf_blackhole(fmt, ##__VA_ARGS__)

Display an DEBUG level log message.

Definition at line 307 of file mmlog.h.

◆ MMLOG_DUMP_DBG

#define MMLOG_DUMP_DBG (   title,
  buf,
  len 
)    mm_hexdump_blackhole(title, buf, len)

Dump the given buffer if DEBUG level logging is enabled.

Definition at line 309 of file mmlog.h.

◆ MMLOG_DUMP_ERR

#define MMLOG_DUMP_ERR (   title,
  buf,
  len 
)    mm_hexdump('E', __func__, __LINE__, (title), (buf), (len))

Dump the given buffer if ERROR level logging is enabled.

Definition at line 268 of file mmlog.h.

◆ MMLOG_DUMP_INF

#define MMLOG_DUMP_INF (   title,
  buf,
  len 
)    mm_hexdump_blackhole(title, buf, len)

Dump the given buffer if INFO level logging is enabled.

Definition at line 297 of file mmlog.h.

◆ MMLOG_DUMP_VRB

#define MMLOG_DUMP_VRB (   title,
  buf,
  len 
)    mm_hexdump_blackhole(title, buf, len)

Dump the given buffer if VERBOSE level logging is enabled.

Definition at line 321 of file mmlog.h.

◆ MMLOG_DUMP_WRN

#define MMLOG_DUMP_WRN (   title,
  buf,
  len 
)    mm_hexdump_blackhole(title, buf, len)

Dump the given buffer if WARNING level logging is enabled.

Definition at line 285 of file mmlog.h.

◆ MMLOG_ERR

#define MMLOG_ERR (   fmt,
  ... 
)    MMLOG(fmt, MMLOG_COLOR_RED, 'E', ##__VA_ARGS__)

Display an ERROR level log message.

Definition at line 266 of file mmlog.h.

◆ MMLOG_INF

#define MMLOG_INF (   fmt,
  ... 
)    printf_blackhole(fmt, ##__VA_ARGS__)

Display an INFO level log message.

Definition at line 295 of file mmlog.h.

◆ MMLOG_LEVEL

#define MMLOG_LEVEL   MMLOG_LEVEL_ERR

The selected log level.

Definition at line 91 of file mmlog.h.

◆ MMLOG_LEVEL_APP

#define MMLOG_LEVEL_APP   (2)

Special log level for always on "application" log messages.

These have a special format.

Definition at line 99 of file mmlog.h.

◆ MMLOG_LEVEL_DBG

#define MMLOG_LEVEL_DBG   (6)

Application, error, warning, info, and debug messages.

Definition at line 107 of file mmlog.h.

◆ MMLOG_LEVEL_ERR

#define MMLOG_LEVEL_ERR   (3)

Application and error messages only.

Definition at line 101 of file mmlog.h.

◆ MMLOG_LEVEL_INF

#define MMLOG_LEVEL_INF   (5)

Application, error, warning, and info messages.

Definition at line 105 of file mmlog.h.

◆ MMLOG_LEVEL_INVALID

#define MMLOG_LEVEL_INVALID   (0)

Invalid log level.

Definition at line 95 of file mmlog.h.

◆ MMLOG_LEVEL_OFF

#define MMLOG_LEVEL_OFF   (1)

Logging disabled.

Definition at line 97 of file mmlog.h.

◆ MMLOG_LEVEL_VRB

#define MMLOG_LEVEL_VRB   (7)

Application, error, warning, info, and debug messages, plus additional verbose messages.

Definition at line 109 of file mmlog.h.

◆ MMLOG_LEVEL_WRN

#define MMLOG_LEVEL_WRN   (4)

Application, error and warning messages only.

Definition at line 103 of file mmlog.h.

◆ MMLOG_PREFIX_ARGS

#define MMLOG_PREFIX_ARGS   lvl, mmosal_get_time_ms(), short_task_name, __func__, __LINE__

Log line prefix arguments (log levels other than APP).

Definition at line 171 of file mmlog.h.

◆ MMLOG_PREFIX_FMT

#define MMLOG_PREFIX_FMT   "%c %8lu %s %s[%d] "

Log line prefix format string (log levels other than APP).

Definition at line 166 of file mmlog.h.

◆ MMLOG_PRINTF

#define MMLOG_PRINTF (   ...)    mmosal_printf(__VA_ARGS__)

Logging printf definition.

Definition at line 233 of file mmlog.h.

◆ MMLOG_SUFFIX_FMT

#define MMLOG_SUFFIX_FMT

Log line suffix format string (log levels other than APP).

Definition at line 176 of file mmlog.h.

◆ MMLOG_VRB

#define MMLOG_VRB (   fmt,
  ... 
)    printf_blackhole(fmt, ##__VA_ARGS__)

Display an VERBOSE level log message.

Definition at line 319 of file mmlog.h.

◆ MMLOG_WRN

#define MMLOG_WRN (   fmt,
  ... 
)    printf_blackhole(fmt, ##__VA_ARGS__)

Display an WARNING level log message.

Definition at line 283 of file mmlog.h.

Function Documentation

◆ mm_hexdump()

void mm_hexdump ( char  level,
const char *  function,
unsigned  line_number,
const char *  title,
const uint8_t *  buf,
size_t  len 
)

Dumps a binary buffer in hex.

Parameters
levelA single character indicating log level.
functionName of function this was invoked from.
line_numberLine number this was invoked from.
titleTitle of the buffer.
bufThe buffer to dump.
lenLength of the buffer.

◆ mm_hexdump_blackhole()

static void mm_hexdump_blackhole ( const char *  title,
const uint8_t *  buf,
size_t  len 
)
inlinestatic

Black hole version of mm_hexdump() to ensure arguments are referenced when a given log level is disabled.

Parameters
titleTitle of the buffer (ignored).
bufThe buffer to dump (ignored).
lenLength of the buffer (ignored).

Definition at line 220 of file mmlog.h.

◆ mm_logging_init()

void mm_logging_init ( void  )

Initialize Morse logging API.

This should be invoked after OS initialization since it will create a mutex for logging.

◆ printf_blackhole()

static int printf_blackhole ( const char *  fmt,
  ... 
)
inlinestatic

Black hole printf to ensure arguments are referenced when a given log level is disabled.

Parameters
fmtThe printf format string.
Returns
0.

Definition at line 206 of file mmlog.h.