34 lines
1.1 KiB
C
34 lines
1.1 KiB
C
#ifndef LOGGER_HEADER
|
|
#define LOGGER_HEADER
|
|
|
|
#include <stdio.h>
|
|
|
|
// 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
|
|
|
|
// Current log level (change at runtime or compile-time)
|
|
#ifndef CURRENT_LOG_LEVEL
|
|
#define CURRENT_LOG_LEVEL LOG_LEVEL_DEBUG
|
|
#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
|