77 #define LOG_LEVEL LOG_LEVEL_DEBUG
85#ifndef _POSIX_C_SOURCE
86 #define _POSIX_C_SOURCE 200809UL
94 #define LOG_PRINTF(file, format, ...) \
95 __builtin_fprintf((FILE *)(file), (format), ##__VA_ARGS__)
97 #define LOG_PRINTF(file, ...) fprintf(file, __VA_ARGS__)
105 #define LOG_VPRINTF(file, format, args) \
106 __builtin_vfprintf((FILE *)(file), (format), (args))
108 #define LOG_VPRINTF(file, fmt, args) vfprintf(file, fmt, args)
115#define PREFIX_ERROR "[ERROR]"
116#define PREFIX_WARNING "[WARNING]"
117#define PREFIX_INFO "[INFO]"
118#define PREFIX_DEBUG "[DEBUG]"
125#define COLOR_RED "\033[0;31m"
126#define COLOR_YELLOW "\033[0;33m"
127#define COLOR_BLUE "\033[0;34m"
128#define COLOR_GREEN "\033[0;32m"
129#define COLOR_RESET "\033[0m"
137 #define ATTR_PRINTF(fmt_idx, var_idx) \
138 __attribute__((format(printf, fmt_idx, var_idx)))
227 int ret = EXIT_SUCCESS;
229 FILE *out = (FILE *)NULL;
231 static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
234 struct tm *ptm = (
struct tm *)NULL;
243 goto function_output;
246 pthread_mutex_lock(&log_mutex);
248 memset(&ts, 0,
sizeof(ts));
250 clock_gettime(CLOCK_REALTIME, &ts);
253 ptm = localtime(&now);
256 msec = ts.tv_nsec / 1000000L;
259 "[%02d:%02d:%02d.%03ld] ",
265 if (isatty(fileno(out)))
275 LOG_PRINTF(out,
" (at %s:%d:%s())\n", file, line, func);
276 pthread_mutex_unlock(&log_mutex);
286#define LOG_ERROR(fmt, ...) \
287 LOG_output(LOG_LEVEL_ERROR, \
300#define LOG_WARNING(fmt, ...) \
301 LOG_output(LOG_LEVEL_WARNING, \
314#define LOG_INFO(fmt, ...) \
315 LOG_output(LOG_LEVEL_INFO, \
328#define LOG_DEBUG(fmt, ...) \
329 LOG_output(LOG_LEVEL_DEBUG, \
#define LOG_LEVEL
Default log level if not defined.
Definition logs.h:74
static int LOG_output(log_level_t level, const char *color, const char *prefix, const char *file, const char *func, int line, const char *fmt,...) __attribute__((format(printf
Internal logging implementation: threadâsafe, prints timestamp, optional ANSI color,...
Definition logs.h:214
#define COLOR_RESET
Definition logs.h:126
#define LOG_VPRINTF(file, fmt, args)
Compiler-specific vprintf abstraction.
Definition logs.h:105
#define ATTR_PRINTF(fmt_idx, var_idx)
Macro to apply GCC printf-style format checking on custom functions.
Definition logs.h:134
log_level_t
Defines log levels for the logging system.
Definition logs.h:58
#define LOG_PRINTF(file,...)
Compiler-specific printf abstraction.
Definition logs.h:94
@ LOG_LEVEL_DEBUG
Definition logs.h:63
@ LOG_LEVEL_ERROR
Definition logs.h:60
@ LOG_LEVEL_WARNING
Definition logs.h:61
@ LOG_LEVEL_NONE
Definition logs.h:59
@ LOG_LEVEL_INFO
Definition logs.h:62