#pragma once #include #ifdef __cplusplus extern "C" { #define LOGGER_VAR_DECL extern "C" { unsigned int logger_verbosity = 0; } #else #define LOGGER_VAR_DECL unsigned int logger_verbosity = 0 #endif extern unsigned int logger_verbosity; static inline void logger_set_verbosity(unsigned int v) { logger_verbosity = v; } static inline unsigned int logger_get_verbosity(void) { return logger_verbosity; } #define DEBUG_VERBOSITY (2) #define INFO_VERBOSITY (1) #define W(fmt, ...) \ do { \ fprintf(stderr, "[WARNING] %s: " fmt, __func__, ##__VA_ARGS__); \ } while (0) #define E(fmt, ...) \ do { \ fprintf(stderr, "[ERROR] %s: " fmt, __func__, ##__VA_ARGS__); \ exit(1); \ } while (0) #define V(fmt, ...) \ do { \ if (logger_get_verbosity() >= INFO_VERBOSITY) { \ fprintf(stdout, "[INFO] %s: " fmt, __func__, ##__VA_ARGS__); \ } \ } while (0) #define D(fmt, ...) \ do { \ if (logger_get_verbosity() >= DEBUG_VERBOSITY) { \ fprintf(stdout, "[DEBUG] %s: " fmt, __func__, ##__VA_ARGS__); \ } \ } while (0) #ifdef __cplusplus } #endif