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
Go to the documentation of this file.
1
5
6#ifndef MESHX_LOG_H
7#define MESHX_LOG_H
8
9#include <stdio.h>
11#include "module_id.h"
12#include "meshx_err.h"
13
18#ifndef CONFIG_MESHX_LOG_PRINTF
19#define CONFIG_MESHX_LOG_PRINTF printf
20#endif /* CONFIG_MESHX_LOG_PRINTF */
21
22#ifndef CONFIG_MESHX_DEFAULT_LOG_LEVEL
23#define CONFIG_MESHX_DEFAULT_LOG_LEVEL MESHX_LOG_INFO
24#endif /* CONFIG_MESHX_DEFAULT_LOG_LEVEL */
25
26/* ANSI Color Codes */
27#define MESHX_LOG_COLOR_BLACK "\033[0;30m"
28#define MESHX_LOG_COLOR_RED "\033[0;31m"
29#define MESHX_LOG_COLOR_GREEN "\033[0;32m"
30#define MESHX_LOG_COLOR_YELLOW "\033[0;33m"
31#define MESHX_LOG_COLOR_BLUE "\033[0;34m"
32#define MESHX_LOG_COLOR_PURPLE "\033[0;35m"
33#define MESHX_LOG_COLOR_CYAN "\033[0;36m"
34#define MESHX_LOG_COLOR_WHITE "\033[0;37m"
35#define MESHX_LOG_COLOR_RESET "\033[0m"
36
37/* Log levels */
38
39#define MESHX_LOG_VERBOSE 0 /* White */
40#define MESHX_LOG_DEBUG 1 /* Blue */
41#define MESHX_LOG_INFO 2 /* Green */
42#define MESHX_LOG_WARN 3 /* Yellow */
43#define MESHX_LOG_ERROR 4 /* Red */
44#define MESHX_LOG_NONE 5 /* Blue */
45#define MESHX_LOG_MAX 6
46
47typedef unsigned meshx_log_level_t;
48
49typedef unsigned int (*millis_t)(void);
50
51typedef struct meshx_logging
52{
53 unsigned def_log_level;
55
56/* Get color for log level */
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)
62
63/* Logging macro with colors */
64#define MESHX_LOG(module_id, level, format, ...) meshx_log_printf(module_id, level, __FILENAME__, __LINE__, format, ##__VA_ARGS__)
65
66#if CONFIG_MESHX_DEFAULT_LOG_LEVEL < MESHX_LOG_MAX
67#define MESHX_LOGE(module_id, format, ...) \
68 do \
69 { \
70 MESHX_LOG(module_id, MESHX_LOG_ERROR, format, ##__VA_ARGS__); \
71 } while (0)
72#else
73#define MESHX_LOGE(module_id, format, ...) \
74 do \
75 { \
76 } while (0) // Prevent empty macro expansion warning
77
78#endif
79
80#if CONFIG_MESHX_DEFAULT_LOG_LEVEL < MESHX_LOG_ERROR
81#define MESHX_LOGW(module_id, format, ...) \
82 do \
83 { \
84 MESHX_LOG(module_id, MESHX_LOG_WARN, format, ##__VA_ARGS__); \
85 } while (0)
86#else
87#define MESHX_LOGW(module_id, format, ...) \
88 do \
89 { \
90 } while (0)
91#endif
92
93#if CONFIG_MESHX_DEFAULT_LOG_LEVEL < MESHX_LOG_WARN
94#define MESHX_LOGI(module_id, format, ...) \
95 do \
96 { \
97 MESHX_LOG(module_id, MESHX_LOG_INFO, format, ##__VA_ARGS__); \
98 } while (0)
99#else
100#define MESHX_LOGI(module_id, format, ...) \
101 do \
102 { \
103 } while (0)
104#endif
105
106#if CONFIG_MESHX_DEFAULT_LOG_LEVEL < MESHX_LOG_INFO
107#define MESHX_LOGD(module_id, format, ...) \
108 do \
109 { \
110 MESHX_LOG(module_id, MESHX_LOG_DEBUG, format, ##__VA_ARGS__); \
111 } while (0)
112#else
113#define MESHX_LOGD(module_id, format, ...) \
114 do \
115 { \
116 } while (0)
117#endif
118
133
154 const char *func, int line_no, const char *fmt, ...);
155
156#endif /* MESHX_LOG_H */
Internal configuration settings for MeshX.
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
#define MESHX_WEEK
Definition meshx_err.h:19
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
unsigned meshx_log_level_t
Definition meshx_log.h:47
struct meshx_logging meshx_logging_t
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.
Definition meshx_log.c:109
unsigned int(* millis_t)(void)
Definition meshx_log.h:49
Defines module IDs for different elements in the BLE mesh node application.
module_id_t
Enumeration of module IDs.
Definition module_id.h:23
unsigned def_log_level
Definition meshx_log.h:53