34#ifndef _UTILS_LOGGING_H_
35#define _UTILS_LOGGING_H_
38#ifndef __STDC_VERSION__
40#define __STDC_VERSION__ 199901L
61#if defined(__linux__) || defined(__MACH__) || defined(GCC_ARMCM3) || defined(GCC_ARMCM0)
66extern os_mutex_t g_log_mutex;
67#define LOCK_LOG os_mutex_lock(&g_log_mutex)
68#define UNLOCK_LOG os_mutex_unlock(&g_log_mutex)
77#define GLOBAL_LOG_OUTPUT ::log_output
81#define GLOBAL_LOG_OUTPUT log_output
85#define LOG_MAYBE_DIE(level) (level == FATAL)
89#define LOG_MAYBE_DIE(level) 0
99#define LOG(level, message...) \
102 if (LOG_MAYBE_DIE(level)) \
106 else if (level == FATAL) \
108 fprintf(stderr, message); \
109 fprintf(stderr, "\n"); \
112 else if (LOGLEVEL >= level) \
115 int sret = snprintf(logbuffer, sizeof(logbuffer), message); \
116 if (sret > (int)sizeof(logbuffer)) \
117 sret = sizeof(logbuffer); \
118 GLOBAL_LOG_OUTPUT(logbuffer, sret); \
124#define LOG_ERROR(message...) LOG(LEVEL_ERROR, message)
126#if defined(__linux__) || defined(__MACH__)
128#elif defined(ESP_PLATFORM)
137#define LOGLEVEL FATAL
174#define ERRNOCHECK(where, x...) \
179 print_errno_and_exit(where); \
static const int VERBOSE
Loglevel that is usually not printed, reporting debugging information.
static const int WARNING
Loglevel that is always printed, reporting a warning or a retryable error.
static const int LEVEL_ERROR
Loglevel that is always printed, reporting an error.
void print_errno_and_exit(const char *where)
Prints an error message about errno to std error and terminates the current program.
char logbuffer[256]
Temporary buffer to sprintf() the log lines into.
static const int INFO
Loglevel that is printed by default, reporting some status information.
static const int ALWAYS
Loglevel that is always printed.
void log_output(char *buf, int size)
Prints a line of log to the log output destination.
static const int FATAL
Loglevel that kills the current process.