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 File Reference

Implementation of the MeshX logging system. More...

#include "meshx_log.h"
#include "module_id.h"
#include "interface/rtos/meshx_rtos_utils.h"
#include <stdio.h>
#include <stdarg.h>
Include dependency graph for meshx_log.c:

Go to the source code of this file.

Functions

meshx_err_t meshx_logging_init (const meshx_logging_t *config)
 Initializes the MeshX logging system with the provided configuration.
 
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.
 
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.
 

Variables

static meshx_log_level_t module_log_level [MODULE_ID_MAX]
 
static const char * log_lvl_str [MESHX_LOG_MAX]
 
static meshx_logging_t meshx_logging_ctrl
 

Detailed Description

Implementation of the MeshX logging system.

This file contains the implementation of the logging system for the MeshX application. It provides functions to initialize the logging system, set logging levels for specific modules, and log formatted messages with different log levels and colors.

The logging system supports different modules identified by module IDs, and each module can have its own logging level. The log levels determine the verbosity of the log messages. The system also supports colored log messages for different log levels.

The logging system requires a configuration structure to be initialized, which includes a default log level and a callback function to retrieve the current time in milliseconds.

The main functions provided are:

  • meshx_logging_init: Initializes the logging system with the provided configuration.
  • meshx_module_set_log_level: Sets the logging level for a specified module.
  • meshx_log_printf: Logs a formatted message for a specified module and log level.

The file also defines macros for logging messages at different levels, such as error, warning, info, and debug.

Author
Pranjal Chanda

Definition in file meshx_log.c.

Function Documentation

◆ 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,
... )

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_COLOR_RESET
Definition meshx_log.h:35
#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:

◆ meshx_module_set_log_level()

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.

This function assigns a new logging level to a given module identified by its module ID. The logging level determines the verbosity of log messages for that module.

Parameters
[in]module_idThe ID of the module whose log level is to be set.
[in]log_levelThe new logging level to be assigned to the module.

Definition at line 85 of file meshx_log.c.

86{
87 module_log_level[module_id] = log_level;
88}

Variable Documentation

◆ log_lvl_str

const char* log_lvl_str[MESHX_LOG_MAX]
static
Initial value:
=
{
"", "D", "I", "W", "E"
}

Definition at line 41 of file meshx_log.c.

42{
43 "", "D", "I", "W", "E"
44};

◆ meshx_logging_ctrl

meshx_logging_t meshx_logging_ctrl
static

Definition at line 46 of file meshx_log.c.

◆ module_log_level

meshx_log_level_t module_log_level[MODULE_ID_MAX]
static

Definition at line 39 of file meshx_log.c.