MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_log.h File Reference

Logging interface for MeshX with color-coded output. More...

#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
#include "meshx_err.h"
#include "module_id.h"
#include "interface/utils/meshx_tiny_printf.h"

Go to the source code of this file.

Data Structures

struct  meshx_logging_t
struct  meshx_log_packet_t
 TLV Log Packet structure. More...

Macros

#define CONFIG_MESHX_LOG_THREADED   0
#define MESHX_LOG_NONE   0
#define MESHX_LOG_ERROR   1
#define MESHX_LOG_WARN   2
#define MESHX_LOG_INFO   3
#define MESHX_LOG_DEBUG   4
#define MESHX_LOG_VERBOSE   5
#define MESHX_LOG_MAX   6
#define MESHX_LOG_COLOR_BLACK   "30"
#define MESHX_LOG_COLOR_RED   "31"
#define MESHX_LOG_COLOR_GREEN   "32"
#define MESHX_LOG_COLOR_BROWN   "33"
#define MESHX_LOG_COLOR_BLUE   "34"
#define MESHX_LOG_COLOR_PURPLE   "35"
#define MESHX_LOG_COLOR_CYAN   "36"
#define MESHX_LOG_COLOR_WHITE   "37"
#define MESHX_LOG_COLOR_RESET   "\033[0m"
#define MESHX_LOG_COLOR(COLOR)
#define MESHX_LOG_COLOR_E   MESHX_LOG_COLOR(MESHX_LOG_COLOR_RED)
#define MESHX_LOG_COLOR_W   MESHX_LOG_COLOR(MESHX_LOG_COLOR_BROWN)
#define MESHX_LOG_COLOR_I   MESHX_LOG_COLOR(MESHX_LOG_COLOR_GREEN)
#define MESHX_LOG_COLOR_D   MESHX_LOG_COLOR(MESHX_LOG_COLOR_BLUE)
#define MESHX_LOG_COLOR_V   MESHX_LOG_COLOR(MESHX_LOG_COLOR_RESET)
#define MESHX_LOG_GET_COLOR(level)
#define CONFIG_MESHX_DEFAULT_LOG_LEVEL   MESHX_LOG_INFO
#define MESHX_LOG_STR_ATTR   __attribute__((section(".meshx_log_str"), used))
#define MESHX_LOG_SYNC_WORD   0xDEAD
#define MESHX_LOG_CONCAT_INNER(a, b)
#define MESHX_LOG_CONCAT(a, b)
#define MESHX_LOG_UNIQUE_ID   __LINE__
#define MESHX_LOG(module_id, level, format, ...)
#define MESHX_STR_INNER(x)
#define MESHX_STR(x)
#define MESHX_LOG_INTERNAL(id, module_id, level, format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, ...)
#define MESHX_LOGE(module_id, format, ...)
#define MESHX_LOGW(module_id, format, ...)
#define MESHX_LOGI(module_id, format, ...)
#define MESHX_LOGD(module_id, format, ...)
#define MESHX_LOGV(module_id, format, ...)
#define CONFIG_MESHX_LOG_PRINTF   meshx_tiny_printf

Typedefs

typedef uint8_t meshx_log_level_t

Functions

meshx_err_t meshx_logging_init (const meshx_logging_t *config)
void meshx_module_set_log_level (module_id_t module_id, meshx_log_level_t log_level)
void meshx_log_packet (module_id_t module_id, meshx_log_level_t log_level, const char *file, int line_no, const char *fmt,...)
 Logs a packetized binary log message.
void meshx_log_printf (module_id_t module_id, meshx_log_level_t log_level, const char *func, int line_no, const char *fmt,...)
 Legacy printf-style logging for external components.

Detailed Description

Logging interface for MeshX with color-coded output.

Macro Definition Documentation

◆ CONFIG_MESHX_DEFAULT_LOG_LEVEL

#define CONFIG_MESHX_DEFAULT_LOG_LEVEL   MESHX_LOG_INFO

◆ CONFIG_MESHX_LOG_PRINTF

#define CONFIG_MESHX_LOG_PRINTF   meshx_tiny_printf

◆ CONFIG_MESHX_LOG_THREADED

#define CONFIG_MESHX_LOG_THREADED   0

◆ MESHX_LOG

#define MESHX_LOG ( module_id,
level,
format,
... )
Value:
MESHX_LOG_INTERNAL(MESHX_LOG_UNIQUE_ID, module_id, level, format, ##__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
#define MESHX_LOG_UNIQUE_ID
Definition meshx_log.h:78
#define MESHX_LOG_INTERNAL(id, module_id, level, format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15,...)
Definition meshx_log.h:105
99#define MESHX_LOG(module_id, level, format, ...) \
100 MESHX_LOG_INTERNAL(MESHX_LOG_UNIQUE_ID, module_id, level, format, ##__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

◆ MESHX_LOG_COLOR

#define MESHX_LOG_COLOR ( COLOR)
Value:
"\033[0;" COLOR "m"

◆ MESHX_LOG_COLOR_BLACK

#define MESHX_LOG_COLOR_BLACK   "30"

◆ MESHX_LOG_COLOR_BLUE

#define MESHX_LOG_COLOR_BLUE   "34"

◆ MESHX_LOG_COLOR_BROWN

#define MESHX_LOG_COLOR_BROWN   "33"

◆ MESHX_LOG_COLOR_CYAN

#define MESHX_LOG_COLOR_CYAN   "36"

◆ MESHX_LOG_COLOR_D

#define MESHX_LOG_COLOR_D   MESHX_LOG_COLOR(MESHX_LOG_COLOR_BLUE)

◆ MESHX_LOG_COLOR_E

#define MESHX_LOG_COLOR_E   MESHX_LOG_COLOR(MESHX_LOG_COLOR_RED)

◆ MESHX_LOG_COLOR_GREEN

#define MESHX_LOG_COLOR_GREEN   "32"

◆ MESHX_LOG_COLOR_I

#define MESHX_LOG_COLOR_I   MESHX_LOG_COLOR(MESHX_LOG_COLOR_GREEN)

◆ MESHX_LOG_COLOR_PURPLE

#define MESHX_LOG_COLOR_PURPLE   "35"

◆ MESHX_LOG_COLOR_RED

#define MESHX_LOG_COLOR_RED   "31"

◆ MESHX_LOG_COLOR_RESET

#define MESHX_LOG_COLOR_RESET   "\033[0m"

◆ MESHX_LOG_COLOR_V

#define MESHX_LOG_COLOR_V   MESHX_LOG_COLOR(MESHX_LOG_COLOR_RESET)

◆ MESHX_LOG_COLOR_W

#define MESHX_LOG_COLOR_W   MESHX_LOG_COLOR(MESHX_LOG_COLOR_BROWN)

◆ MESHX_LOG_COLOR_WHITE

#define MESHX_LOG_COLOR_WHITE   "37"

◆ MESHX_LOG_CONCAT

#define MESHX_LOG_CONCAT ( a,
b )
Value:
#define MESHX_LOG_CONCAT_INNER(a, b)
Definition meshx_log.h:72

◆ MESHX_LOG_CONCAT_INNER

#define MESHX_LOG_CONCAT_INNER ( a,
b )
Value:
a ## b

◆ MESHX_LOG_DEBUG

#define MESHX_LOG_DEBUG   4

◆ MESHX_LOG_ERROR

#define MESHX_LOG_ERROR   1

◆ MESHX_LOG_GET_COLOR

#define MESHX_LOG_GET_COLOR ( level)
Value:
#define MESHX_LOG_INFO
Definition meshx_log.h:29
#define MESHX_LOG_COLOR_RESET
Definition meshx_log.h:50
#define MESHX_LOG_COLOR_W
Definition meshx_log.h:54
#define MESHX_LOG_DEBUG
Definition meshx_log.h:30
#define MESHX_LOG_COLOR_I
Definition meshx_log.h:55
#define MESHX_LOG_COLOR_BLUE
Definition meshx_log.h:46
#define MESHX_LOG_COLOR_E
Definition meshx_log.h:53
#define MESHX_LOG_WARN
Definition meshx_log.h:28
#define MESHX_LOG_ERROR
Definition meshx_log.h:27
59#define MESHX_LOG_GET_COLOR(level) ((level) == MESHX_LOG_ERROR ? MESHX_LOG_COLOR_E : \
60 (level) == MESHX_LOG_WARN ? MESHX_LOG_COLOR_W : \
61 (level) == MESHX_LOG_INFO ? MESHX_LOG_COLOR_I : \
62 (level) == MESHX_LOG_DEBUG ? MESHX_LOG_COLOR_BLUE : \
63 MESHX_LOG_COLOR_RESET)

◆ MESHX_LOG_INFO

#define MESHX_LOG_INFO   3

◆ MESHX_LOG_INTERNAL

#define MESHX_LOG_INTERNAL ( id,
module_id,
level,
format,
arg0,
arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7,
arg8,
arg9,
arg10,
arg11,
arg12,
arg13,
arg14,
arg15,
... )
Value:
do \
{ \
static const char MESHX_LOG_CONCAT(_fmt, id)[] __attribute__((section(".meshx_log_str." MESHX_STR(id)), used)) = format; \
static const char MESHX_LOG_CONCAT(_file, id)[] __attribute__((section(".meshx_log_str." MESHX_STR(id)), used)) = __FILE__; \
meshx_log_packet(module_id, level, MESHX_LOG_CONCAT(_file, id), __LINE__, MESHX_LOG_CONCAT(_fmt, id), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); \
} while (0)
#define MESHX_LOG_CONCAT(a, b)
Definition meshx_log.h:73
#define MESHX_STR(x)
Definition meshx_log.h:103
105#define MESHX_LOG_INTERNAL(id, module_id, level, format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, ...) \
106 do \
107 { \
108 static const char MESHX_LOG_CONCAT(_fmt, id)[] __attribute__((section(".meshx_log_str." MESHX_STR(id)), used)) = format; \
109 static const char MESHX_LOG_CONCAT(_file, id)[] __attribute__((section(".meshx_log_str." MESHX_STR(id)), used)) = __FILE__; \
110 meshx_log_packet(module_id, level, MESHX_LOG_CONCAT(_file, id), __LINE__, MESHX_LOG_CONCAT(_fmt, id), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); \
111 } while (0)

◆ MESHX_LOG_MAX

#define MESHX_LOG_MAX   6

◆ MESHX_LOG_NONE

#define MESHX_LOG_NONE   0

◆ MESHX_LOG_STR_ATTR

#define MESHX_LOG_STR_ATTR   __attribute__((section(".meshx_log_str"), used))

◆ MESHX_LOG_SYNC_WORD

#define MESHX_LOG_SYNC_WORD   0xDEAD

◆ MESHX_LOG_UNIQUE_ID

#define MESHX_LOG_UNIQUE_ID   __LINE__

◆ MESHX_LOG_VERBOSE

#define MESHX_LOG_VERBOSE   5

◆ MESHX_LOG_WARN

#define MESHX_LOG_WARN   2

◆ MESHX_LOGD

#define MESHX_LOGD ( module_id,
format,
... )
Value:
do \
{ \
MESHX_LOG(module_id, MESHX_LOG_DEBUG, format, ##__VA_ARGS__); \
} while (0)
132#define MESHX_LOGD(module_id, format, ...) \
133 do \
134 { \
135 MESHX_LOG(module_id, MESHX_LOG_DEBUG, format, ##__VA_ARGS__); \
136 } while (0)

◆ MESHX_LOGE

#define MESHX_LOGE ( module_id,
format,
... )
Value:
do \
{ \
MESHX_LOG(module_id, MESHX_LOG_ERROR, format, ##__VA_ARGS__); \
} while (0)
114#define MESHX_LOGE(module_id, format, ...) \
115 do \
116 { \
117 MESHX_LOG(module_id, MESHX_LOG_ERROR, format, ##__VA_ARGS__); \
118 } while (0)

◆ MESHX_LOGI

#define MESHX_LOGI ( module_id,
format,
... )
Value:
do \
{ \
MESHX_LOG(module_id, MESHX_LOG_INFO, format, ##__VA_ARGS__); \
} while (0)
126#define MESHX_LOGI(module_id, format, ...) \
127 do \
128 { \
129 MESHX_LOG(module_id, MESHX_LOG_INFO, format, ##__VA_ARGS__); \
130 } while (0)

◆ MESHX_LOGV

#define MESHX_LOGV ( module_id,
format,
... )
Value:
do \
{ \
MESHX_LOG(module_id, MESHX_LOG_VERBOSE, format, ##__VA_ARGS__);\
} while (0)
#define MESHX_LOG_VERBOSE
Definition meshx_log.h:31
138#define MESHX_LOGV(module_id, format, ...) \
139 do \
140 { \
141 MESHX_LOG(module_id, MESHX_LOG_VERBOSE, format, ##__VA_ARGS__);\
142 } while (0)

◆ MESHX_LOGW

#define MESHX_LOGW ( module_id,
format,
... )
Value:
do \
{ \
MESHX_LOG(module_id, MESHX_LOG_WARN, format, ##__VA_ARGS__); \
} while (0)
120#define MESHX_LOGW(module_id, format, ...) \
121 do \
122 { \
123 MESHX_LOG(module_id, MESHX_LOG_WARN, format, ##__VA_ARGS__); \
124 } while (0)

◆ MESHX_STR

#define MESHX_STR ( x)
Value:
#define MESHX_STR_INNER(x)
Definition meshx_log.h:102

◆ MESHX_STR_INNER

#define MESHX_STR_INNER ( x)
Value:
#x

Typedef Documentation

◆ meshx_log_level_t

typedef uint8_t meshx_log_level_t

Function Documentation

◆ meshx_log_packet()

void meshx_log_packet ( module_id_t module_id,
meshx_log_level_t log_level,
const char * file,
int line_no,
const char * fmt,
... )

Logs a packetized binary log message.

Note
This is called by the MESHX_LOG macro.
223{
224 va_list args;
225 va_start(args, fmt);
226 vmeshx_log_packet(module_id, log_level, file, line_no, fmt, args);
227 va_end(args);
228}
static void vmeshx_log_packet(module_id_t module_id, meshx_log_level_t log_level, const char *file, int line_no, const char *fmt, va_list args)
Definition meshx_log.c:132

◆ meshx_log_printf()

void meshx_log_printf ( module_id_t module_id,
meshx_log_level_t log_level,
const char * func,
int line_no,
const char * fmt,
... )

Legacy printf-style logging for external components.

232{
233 va_list args;
234 va_start(args, fmt);
235 vmeshx_log_packet(module_id, log_level, func, line_no, fmt, args);
236 va_end(args);
237}

◆ meshx_logging_init()

meshx_err_t meshx_logging_init ( const meshx_logging_t * config)
89{
90 if (!config)
91 return MESHX_INVALID_ARG;
92
93 meshx_logging_ctrl.def_log_level = config->def_log_level;
94 for (size_t i = 0; i < MODULE_ID_MAX; i++)
95 {
97 }
98
99#if CONFIG_MESHX_LOG_THREADED
100 if (!log_threaded_init_done)
101 {
102 meshx_err_t err = meshx_msg_q_create(&log_msg_q);
103 if (err != MESHX_SUCCESS)
104 return err;
105
106 static meshx_task_t log_task;
107 log_task.task_cb = meshx_log_task_handler;
108 log_task.task_name = "meshx_log_task";
109 log_task.stack_size = CONFIG_MESHX_LOG_STACK_SIZE;
111 log_task.arg = NULL;
112
113 err = meshx_task_create(&log_task);
114 if (err != MESHX_SUCCESS)
115 return err;
116
117 log_threaded_init_done = true;
118 }
119#endif
120
121 return MESHX_SUCCESS;
122}
#define CONFIG_MESHX_LOG_TASK_PRIO
Logging task priority configuration.
Definition meshx_control_task.h:43
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
static meshx_logging_t meshx_logging_ctrl
Definition meshx_log.c:73
static meshx_log_level_t module_log_level[MODULE_ID_MAX]
Definition meshx_log.c:72
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
meshx_err_t meshx_msg_q_create(meshx_msg_q_t *msg_q_handle)
Create a MeshX Message Queue.
struct meshx_task meshx_task_t
MeshX Task Structure.
meshx_err_t meshx_task_create(meshx_task_t *task_handle)
Create a MeshX Task.
@ MODULE_ID_MAX
Definition module_id.h:51
meshx_log_level_t def_log_level
Definition meshx_log.h:38
const char * task_name
Definition meshx_task.h:34
size_t stack_size
Definition meshx_task.h:36
int priority
Definition meshx_task.h:37
void * arg
Definition meshx_task.h:35
meshx_task_cb_t task_cb
Definition meshx_task.h:38

◆ meshx_module_set_log_level()

void meshx_module_set_log_level ( module_id_t module_id,
meshx_log_level_t log_level )
125{
126 if (module_id < MODULE_ID_MAX)
127 {
128 module_log_level[module_id] = log_level;
129 }
130}