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.c
Go to the documentation of this file.
1
32
33#include "meshx_log.h"
34#include "module_id.h"
36#include <stdio.h>
37#include <stdarg.h>
38
40
41static const char * log_lvl_str [MESHX_LOG_MAX] =
42{
43 "", "D", "I", "W", "E"
44};
45
47
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}
74
86{
87 module_log_level[module_id] = log_level;
88}
89
110 const char *func, int line_no, const char *fmt, ...)
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}
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
void meshx_module_set_log_level(module_id_t module_id, meshx_log_level_t log_level)
Sets the logging level for a specified module.
Definition meshx_log.c:85
meshx_err_t meshx_logging_init(const meshx_logging_t *config)
Initializes the MeshX logging system with the provided configuration.
Definition meshx_log.c:61
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
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
Logging interface for MeshX with color-coded output.
#define MESHX_LOG_COLOR_RESET
Definition meshx_log.h:35
#define MESHX_LOG_LEVEL_COLOR(level)
Definition meshx_log.h:57
unsigned meshx_log_level_t
Definition meshx_log.h:47
#define MESHX_LOG_MAX
Definition meshx_log.h:45
#define CONFIG_MESHX_DEFAULT_LOG_LEVEL
Definition meshx_log.h:23
struct meshx_logging meshx_logging_t
#define CONFIG_MESHX_LOG_PRINTF
Macro to define printf function.
Definition meshx_log.h:19
Utility functions for RTOS operations in the MeshX framework.
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.
Defines module IDs for different elements in the BLE mesh node application.
module_id_t
Enumeration of module IDs.
Definition module_id.h:23
@ MODULE_ID_MAX
Definition module_id.h:34
unsigned def_log_level
Definition meshx_log.h:53