really still wip
This commit is contained in:
@@ -1,20 +1,33 @@
|
||||
#ifndef LOGGER_HEADER
|
||||
#define LOGGER_HEADER
|
||||
|
||||
// Define log levels
|
||||
#define LOG_ERROR "E"
|
||||
#define LOG_WARN "W"
|
||||
#define LOG_INFO "I"
|
||||
#define LOG_DEBUG "D"
|
||||
#include <stdio.h>
|
||||
|
||||
// Define a generic log macro
|
||||
#define LOG_PRINT(level, tag, fmt, ...) \
|
||||
printf("[%s] %s: " fmt "\r\n", level, tag, ##__VA_ARGS__)
|
||||
// Log levels as integers for easy comparison
|
||||
#define LOG_LEVEL_ERROR 0
|
||||
#define LOG_LEVEL_WARN 1
|
||||
#define LOG_LEVEL_INFO 2
|
||||
#define LOG_LEVEL_DEBUG 3
|
||||
#define LOG_LEVEL_VERBOSE 4
|
||||
|
||||
// Define ESP-like shortcuts
|
||||
#define ESP_LOGE(tag, fmt, ...) LOG_PRINT(LOG_ERROR, tag, fmt, ##__VA_ARGS__)
|
||||
#define ESP_LOGW(tag, fmt, ...) LOG_PRINT(LOG_WARN, tag, fmt, ##__VA_ARGS__)
|
||||
#define ESP_LOGI(tag, fmt, ...) LOG_PRINT(LOG_INFO, tag, fmt, ##__VA_ARGS__)
|
||||
#define ESP_LOGD(tag, fmt, ...) LOG_PRINT(LOG_DEBUG, tag, fmt, ##__VA_ARGS__)
|
||||
// Current log level (change at runtime or compile-time)
|
||||
#ifndef CURRENT_LOG_LEVEL
|
||||
#define CURRENT_LOG_LEVEL LOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
#endif
|
||||
// Internal macro to check log level
|
||||
#define LOG_PRINT_IF(level, levelStr, tag, fmt, ...) \
|
||||
do { \
|
||||
if ((level) <= CURRENT_LOG_LEVEL) { \
|
||||
printf("[%s] %s: " fmt "\r\n", levelStr, tag, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
// ESP-like shortcuts
|
||||
#define MESH_LOGE(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_ERROR, "E", tag, fmt, ##__VA_ARGS__)
|
||||
#define MESH_LOGW(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_WARN, "W", tag, fmt, ##__VA_ARGS__)
|
||||
#define MESH_LOGI(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_INFO, "I", tag, fmt, ##__VA_ARGS__)
|
||||
#define MESH_LOGD(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_DEBUG, "D", tag, fmt, ##__VA_ARGS__)
|
||||
#define MESH_LOGV(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_VERBOSE, "V", tag, fmt, ##__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user