diff options
Diffstat (limited to 'util/log.hpp')
-rw-r--r-- | util/log.hpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/util/log.hpp b/util/log.hpp index 13a2b03..3b6da72 100644 --- a/util/log.hpp +++ b/util/log.hpp @@ -34,9 +34,43 @@ namespace util { +#define WSI_DEFAULT_LOG_LEVEL 1 -#define WSI_LOG_ERROR(fmt, x...) LOGE(fmt, ##x) -#define WSI_LOG_WARNING(fmt, x...) LOGW(fmt, ##x) -#define WSI_LOG_INFO(fmt, x...) LOGI(fmt, ##x) +/** + * @brief Log a message to a certain log level + * + * @details For the log level, we use a bigger integer to represent an increased + * level of verbosity. If this is not specified, the log level is default to 1. + * We use a "staircase" approach with respect to printing logs. We print all log + * messages equal or below the log level set, e.g. if VULKAN_WSI_DEBUG_LEVEL + * is set to 2, messages with log level 1 and 2 are printed. Please note that + * the newline character '\n' is automatically appended. + * + * @param[in] level The log level of this message, you can set an arbitary + * integer however please refer to the included macros for + * the sensible defaults. + * @param[in] file The source file name (``__FILE__``) + * @param[in] line The source file line number (``__LINE__``) + * @param[in] format A C-style formatting string. + */ + +void wsi_log_message(int level, const char *file, int line, const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 4, 5))) +#endif + ; + +#ifdef NDEBUG +static constexpr bool wsi_log_enable = false; +#else +static constexpr bool wsi_log_enable = true; +#endif + +#define WSI_LOG(level, ...) \ + do { if (::util::wsi_log_enable) ::util::wsi_log_message(level, __FILE__, __LINE__, __VA_ARGS__); } while (0) + +#define WSI_LOG_ERROR(...) WSI_LOG(1, __VA_ARGS__) +#define WSI_LOG_WARNING(...) WSI_LOG(2, __VA_ARGS__) +#define WSI_LOG_INFO(...) WSI_LOG(3, __VA_ARGS__) } /* namespace util */ |