MeshX 0.3
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 "meshx_config_internal.h"
#include "module_id.h"
#include "meshx_err.h"
Include dependency graph for meshx_log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  meshx_logging
 

Macros

#define CONFIG_MESHX_LOG_PRINTF   printf
 Macro to define printf function.
 
#define CONFIG_MESHX_DEFAULT_LOG_LEVEL   MESHX_LOG_INFO
 
#define MESHX_LOG_COLOR_BLACK   "\033[0;30m"
 
#define MESHX_LOG_COLOR_RED   "\033[0;31m"
 
#define MESHX_LOG_COLOR_GREEN   "\033[0;32m"
 
#define MESHX_LOG_COLOR_YELLOW   "\033[0;33m"
 
#define MESHX_LOG_COLOR_BLUE   "\033[0;34m"
 
#define MESHX_LOG_COLOR_PURPLE   "\033[0;35m"
 
#define MESHX_LOG_COLOR_CYAN   "\033[0;36m"
 
#define MESHX_LOG_COLOR_WHITE   "\033[0;37m"
 
#define MESHX_LOG_COLOR_RESET   "\033[0m"
 
#define MESHX_LOG_VERBOSE   0 /* White */
 
#define MESHX_LOG_DEBUG   1 /* Blue */
 
#define MESHX_LOG_INFO   2 /* Green */
 
#define MESHX_LOG_WARN   3 /* Yellow */
 
#define MESHX_LOG_ERROR   4 /* Red */
 
#define MESHX_LOG_NONE   5 /* Blue */
 
#define MESHX_LOG_MAX   6
 
#define MESHX_LOG_LEVEL_COLOR(level)
 
#define MESHX_LOG(module_id, level, format, ...)
 
#define MESHX_LOGE(module_id, format, ...)
 
#define MESHX_LOGW(module_id, format, ...)
 
#define MESHX_LOGI(module_id, format, ...)
 
#define MESHX_LOGD(module_id, format, ...)
 

Typedefs

typedef unsigned meshx_log_level_t
 
typedef unsigned int(* millis_t) (void)
 
typedef struct meshx_logging meshx_logging_t
 

Functions

meshx_err_t meshx_logging_init (const meshx_logging_t *config)
 Initializes the MeshX logging system with the provided configuration.
 
MESHX_WEEK void meshx_log_printf (module_id_t module_id, meshx_log_level_t log_level, const char *func, int line_no, const char *fmt,...)
 Logs a formatted message for a specified module and log level.
 

Detailed Description

Logging interface for MeshX with color-coded output.

Definition in file meshx_log.h.

Macro Definition Documentation

◆ CONFIG_MESHX_DEFAULT_LOG_LEVEL

#define CONFIG_MESHX_DEFAULT_LOG_LEVEL   MESHX_LOG_INFO

Definition at line 23 of file meshx_log.h.

◆ CONFIG_MESHX_LOG_PRINTF

#define CONFIG_MESHX_LOG_PRINTF   printf

Macro to define printf function.

Note
this can be overriden by compile time Macro def

Definition at line 19 of file meshx_log.h.

◆ MESHX_LOG

#define MESHX_LOG ( module_id,
level,
format,
... )
Value:
meshx_log_printf(module_id, level, __FILENAME__, __LINE__, format, ##__VA_ARGS__)
void meshx_log_printf(module_id_t module_id, meshx_log_level_t log_level, const char *func, int line_no, const char *fmt,...)
Logs a formatted message for a specified module and log level.
Definition meshx_log.c:109

Definition at line 64 of file meshx_log.h.

◆ MESHX_LOG_COLOR_BLACK

#define MESHX_LOG_COLOR_BLACK   "\033[0;30m"

Definition at line 27 of file meshx_log.h.

◆ MESHX_LOG_COLOR_BLUE

#define MESHX_LOG_COLOR_BLUE   "\033[0;34m"

Definition at line 31 of file meshx_log.h.

◆ MESHX_LOG_COLOR_CYAN

#define MESHX_LOG_COLOR_CYAN   "\033[0;36m"

Definition at line 33 of file meshx_log.h.

◆ MESHX_LOG_COLOR_GREEN

#define MESHX_LOG_COLOR_GREEN   "\033[0;32m"

Definition at line 29 of file meshx_log.h.

◆ MESHX_LOG_COLOR_PURPLE

#define MESHX_LOG_COLOR_PURPLE   "\033[0;35m"

Definition at line 32 of file meshx_log.h.

◆ MESHX_LOG_COLOR_RED

#define MESHX_LOG_COLOR_RED   "\033[0;31m"

Definition at line 28 of file meshx_log.h.

◆ MESHX_LOG_COLOR_RESET

#define MESHX_LOG_COLOR_RESET   "\033[0m"

Definition at line 35 of file meshx_log.h.

◆ MESHX_LOG_COLOR_WHITE

#define MESHX_LOG_COLOR_WHITE   "\033[0;37m"

Definition at line 34 of file meshx_log.h.

◆ MESHX_LOG_COLOR_YELLOW

#define MESHX_LOG_COLOR_YELLOW   "\033[0;33m"

Definition at line 30 of file meshx_log.h.

◆ MESHX_LOG_DEBUG

#define MESHX_LOG_DEBUG   1 /* Blue */

Definition at line 40 of file meshx_log.h.

◆ MESHX_LOG_ERROR

#define MESHX_LOG_ERROR   4 /* Red */

Definition at line 43 of file meshx_log.h.

◆ MESHX_LOG_INFO

#define MESHX_LOG_INFO   2 /* Green */

Definition at line 41 of file meshx_log.h.

◆ MESHX_LOG_LEVEL_COLOR

#define MESHX_LOG_LEVEL_COLOR ( level)
Value:
( \
#define MESHX_LOG_INFO
Definition meshx_log.h:41
#define MESHX_LOG_COLOR_RESET
Definition meshx_log.h:35
#define MESHX_LOG_DEBUG
Definition meshx_log.h:40
#define MESHX_LOG_COLOR_RED
Definition meshx_log.h:28
#define MESHX_LOG_COLOR_BLUE
Definition meshx_log.h:31
#define MESHX_LOG_WARN
Definition meshx_log.h:42
#define MESHX_LOG_ERROR
Definition meshx_log.h:43
#define MESHX_LOG_COLOR_GREEN
Definition meshx_log.h:29
#define MESHX_LOG_COLOR_YELLOW
Definition meshx_log.h:30

Definition at line 57 of file meshx_log.h.

57#define MESHX_LOG_LEVEL_COLOR(level) ( \
58 (level) == MESHX_LOG_ERROR ? MESHX_LOG_COLOR_RED : (level) == MESHX_LOG_WARN ? MESHX_LOG_COLOR_YELLOW \
59 : (level) == MESHX_LOG_INFO ? MESHX_LOG_COLOR_GREEN \
60 : (level) == MESHX_LOG_DEBUG ? MESHX_LOG_COLOR_BLUE \
61 : MESHX_LOG_COLOR_RESET)

◆ MESHX_LOG_MAX

#define MESHX_LOG_MAX   6

Definition at line 45 of file meshx_log.h.

◆ MESHX_LOG_NONE

#define MESHX_LOG_NONE   5 /* Blue */

Definition at line 44 of file meshx_log.h.

◆ MESHX_LOG_VERBOSE

#define MESHX_LOG_VERBOSE   0 /* White */

Definition at line 39 of file meshx_log.h.

◆ MESHX_LOG_WARN

#define MESHX_LOG_WARN   3 /* Yellow */

Definition at line 42 of file meshx_log.h.

◆ MESHX_LOGD

#define MESHX_LOGD ( module_id,
format,
... )
Value:
do \
{ \
} while (0)

Definition at line 113 of file meshx_log.h.

113#define MESHX_LOGD(module_id, format, ...) \
114 do \
115 { \
116 } while (0)

◆ MESHX_LOGE

#define MESHX_LOGE ( module_id,
format,
... )
Value:
do \
{ \
} while (0)

Definition at line 73 of file meshx_log.h.

73#define MESHX_LOGE(module_id, format, ...) \
74 do \
75 { \
76 } while (0) // Prevent empty macro expansion warning

◆ MESHX_LOGI

#define MESHX_LOGI ( module_id,
format,
... )
Value:
do \
{ \
} while (0)

Definition at line 100 of file meshx_log.h.

100#define MESHX_LOGI(module_id, format, ...) \
101 do \
102 { \
103 } while (0)

◆ MESHX_LOGW

#define MESHX_LOGW ( module_id,
format,
... )
Value:
do \
{ \
} while (0)

Definition at line 87 of file meshx_log.h.

87#define MESHX_LOGW(module_id, format, ...) \
88 do \
89 { \
90 } while (0)

Typedef Documentation

◆ meshx_log_level_t

typedef unsigned meshx_log_level_t

Definition at line 47 of file meshx_log.h.

◆ meshx_logging_t

◆ millis_t

typedef unsigned int(* millis_t) (void)

Definition at line 49 of file meshx_log.h.

Function Documentation

◆ meshx_log_printf()

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

Logs a formatted message for a specified module and log level.

Note
This is a weak function, can be redefined to override in app layer

This function checks if the provided module ID and log level are valid and above the current global and module-specific log levels. If valid, it processes the variable arguments to format and log the message.

Note
This is a weak function defination and can be overriden by any other version of defination required as per platform
Parameters
[in]module_idThe ID of the module for which the log is generated.
[in]log_levelThe log level of the message.
[in]funcThe name of the function where the log is called.
[in]line_noThe line number in the source code where the log is called.
[in]fmtThe format string for the log message.
[in]...Additional arguments for the format string.

Definition at line 109 of file meshx_log.c.

111{
112 /* Validate module ID */
113 if (module_id > MODULE_ID_MAX || log_level < meshx_logging_ctrl.def_log_level || module_log_level[module_id] < meshx_logging_ctrl.def_log_level)
114 return;
115
116 /* Get timestamp */
117 unsigned int millis;
118 unsigned int task_id;
119
122 /* Get log level color */
123 const char *color = MESHX_LOG_LEVEL_COLOR(log_level);
124
125 /* Print timestamp and log */
126 CONFIG_MESHX_LOG_PRINTF("\r%s[%s][%08u][%03x][%25s:%04d]\t", color, log_lvl_str[log_level], millis, task_id, func, line_no);
127
128 /* Process variable arguments */
129 va_list args;
130 va_start(args, fmt);
131 vprintf(fmt, args);
132 va_end(args);
133 /* Reset color and add newline */
135}
static meshx_logging_t meshx_logging_ctrl
Definition meshx_log.c:46
static meshx_log_level_t module_log_level[MODULE_ID_MAX]
Definition meshx_log.c:39
static const char * log_lvl_str[MESHX_LOG_MAX]
Definition meshx_log.c:41
#define MESHX_LOG_LEVEL_COLOR(level)
Definition meshx_log.h:57
#define CONFIG_MESHX_LOG_PRINTF
Macro to define printf function.
Definition meshx_log.h:19
meshx_err_t meshx_rtos_get_sys_time(unsigned int *millis)
Retrieves the current system time in milliseconds.
Definition meshx_utils.c:36
meshx_err_t meshx_rtos_get_curr_task_id_prio(unsigned int *task_id)
Retrieves the current task ID.
@ MODULE_ID_MAX
Definition module_id.h:34
Here is the call graph for this function:

◆ meshx_logging_init()

meshx_err_t meshx_logging_init ( const meshx_logging_t * config)

Initializes the MeshX logging system with the provided configuration.

This function sets up the logging system by assigning the default log level and the callback function for retrieving the current time in milliseconds. It validates the configuration parameters and returns an error if they are invalid.

Parameters
[in]configPointer to the logging configuration structure.
Returns
MESHX_SUCCESS on successful initialization, MESHX_INVALID_ARG if the configuration is invalid.

Definition at line 61 of file meshx_log.c.

62{
63 if (!config)
64 return MESHX_INVALID_ARG;
65
66 meshx_logging_ctrl.def_log_level = config->def_log_level;
67 for (size_t i = 0; i < MODULE_ID_MAX; i++)
68 {
70 }
71
72 return MESHX_SUCCESS;
73}
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
#define CONFIG_MESHX_DEFAULT_LOG_LEVEL
Definition meshx_log.h:23
unsigned def_log_level
Definition meshx_log.h:53
Here is the caller graph for this function: