43#if defined(__GNUC__) || defined(__clang__)
44 #define __FUNC_NAME__ __func__
46 #define __FUNC_NAME__ __FUNCTION__
60#define UNIOT_LOG_LEVEL_ERROR 0
61#define UNIOT_LOG_LEVEL_WARN 1
62#define UNIOT_LOG_LEVEL_INFO 2
63#define UNIOT_LOG_LEVEL_DEBUG 3
64#define UNIOT_LOG_LEVEL_TRACE 4
72#ifndef UNIOT_LOG_LEVEL
73#define UNIOT_LOG_LEVEL UNIOT_LOG_LEVEL_DEBUG
91#ifndef UNIOT_LOG_STREAM
92#define UNIOT_LOG_STREAM Serial
101#ifndef UNIOT_LOG_BAUD_RATE
102#define UNIOT_LOG_BAUD_RATE 115200
111#ifndef UNIOT_LOG_BUF_SIZE
112#define UNIOT_LOG_BUF_SIZE 256
121#ifndef UNIOT_LOG_SET_READY
122#define UNIOT_LOG_SET_READY() \
124 if (!UNIOT_LOG_STREAM) { \
125 UNIOT_LOG_STREAM.begin(UNIOT_LOG_BAUD_RATE); \
126 UNIOT_LOG_STREAM.print("\n\n"); \
137#ifndef UNIOT_LOG_PRINT
138#define UNIOT_LOG_PRINT(...) \
140 if (UNIOT_LOG_STREAM) \
141 UNIOT_LOG_STREAM.print(__VA_ARGS__); \
159#define UNIOT_LOG(log_type, log_fmt, log_arg...) \
161 uniot_log_printf("[" #log_type "][%lu][%s:%d][%s] " log_fmt "\n", \
162 millis(), __FILE__, __LINE__, __FUNC_NAME__, ##log_arg); \
175#define UNIOT_LOG_IF(log_type, log_cond, log_fmt, log_arg...) \
178 UNIOT_LOG(log_type, log_fmt, ##log_arg); \
192uniot_log_printf(
const char *format, ...) {
194 va_start(arg, format);
196 int len = vsnprintf(buf,
sizeof(buf), format, arg);
199 if (len >= (
int)
sizeof(buf))
213#define UNIOT_LOG_SET_READY() do {} while(0)
214#define UNIOT_LOG_PRINT(...) (UNUSED(__VA_ARGS__))
215#define UNIOT_LOG(log_type, ...) (UNUSED(__VA_ARGS__))
216#define UNIOT_LOG_IF(log_type, ...) (UNUSED(__VA_ARGS__))
219#if UNIOT_LOG_LEVEL_ERROR <= UNIOT_LOG_LEVEL
226#define UNIOT_LOG_ERROR(...) UNIOT_LOG(ERROR, __VA_ARGS__)
234#define UNIOT_LOG_ERROR_IF(log_cond, log...) UNIOT_LOG_IF(ERROR, log_cond, ##log)
236#define UNIOT_LOG_ERROR(...) (UNUSED(__VA_ARGS__))
237#define UNIOT_LOG_ERROR_IF(...) (UNUSED(__VA_ARGS__))
240#if UNIOT_LOG_LEVEL_WARN <= UNIOT_LOG_LEVEL
247#define UNIOT_LOG_WARN(...) UNIOT_LOG(WARN, __VA_ARGS__)
255#define UNIOT_LOG_WARN_IF(log_cond, log...) UNIOT_LOG_IF(WARN, log_cond, ##log)
257#define UNIOT_LOG_WARN(...) (UNUSED(__VA_ARGS__))
258#define UNIOT_LOG_WARN_IF(...) (UNUSED(__VA_ARGS__))
261#if UNIOT_LOG_LEVEL_INFO <= UNIOT_LOG_LEVEL
268#define UNIOT_LOG_INFO(...) UNIOT_LOG(INFO, __VA_ARGS__)
276#define UNIOT_LOG_INFO_IF(log_cond, log...) UNIOT_LOG_IF(INFO, log_cond, ##log)
282#define UNIOT_LOG_INFO(...) (UNUSED(__VA_ARGS__))
283#define UNIOT_LOG_INFO_IF(...) (UNUSED(__VA_ARGS__))
286#if UNIOT_LOG_LEVEL_DEBUG <= UNIOT_LOG_LEVEL
293#define UNIOT_LOG_DEBUG(...) UNIOT_LOG(DEBUG, __VA_ARGS__)
301#define UNIOT_LOG_DEBUG_IF(log_cond, log...) UNIOT_LOG_IF(DEBUG, log_cond, ##log)
303#define UNIOT_LOG_DEBUG(...) (UNUSED(__VA_ARGS__))
304#define UNIOT_LOG_DEBUG_IF(...) (UNUSED(__VA_ARGS__))
307#if UNIOT_LOG_LEVEL_TRACE <= UNIOT_LOG_LEVEL
314#define UNIOT_LOG_TRACE(...) UNIOT_LOG(TRACE, __VA_ARGS__)
322#define UNIOT_LOG_TRACE_IF(log_cond, log...) UNIOT_LOG_IF(TRACE, log_cond, ##log)
324#define UNIOT_LOG_TRACE(...) (UNUSED(__VA_ARGS__))
325#define UNIOT_LOG_TRACE_IF(...) (UNUSED(__VA_ARGS__))
#define UNIOT_LOG_BUF_SIZE
Maximum size of the logging buffer.
Definition Logger.h:112
#define UNIOT_LOG_PRINT(...)
Print to the logging stream.
Definition Logger.h:138