1 /* 2 * This is a stable interface of wlroots. Future changes will be limited to: 3 * 4 * - New functions 5 * - New struct members 6 * - New enum members 7 * 8 * Note that wlroots does not make an ABI compatibility promise - in the future, 9 * the layout and size of structs used by wlroots may change, requiring code 10 * depending on this header to be recompiled (but not edited). 11 * 12 * Breaking changes are announced by email and follow a 1-year deprecation 13 * schedule. Send an email to ~sircmpwn/wlroots-announce+subscribe@lists.sr.ht 14 * to receive these announcements. 15 */ 16 17 #ifndef WLR_UTIL_LOG_H 18 #define WLR_UTIL_LOG_H 19 20 #include <stdbool.h> 21 #include <stdarg.h> 22 #include <string.h> 23 #include <errno.h> 24 25 enum wlr_log_importance { 26 WLR_SILENT = 0, 27 WLR_ERROR = 1, 28 WLR_INFO = 2, 29 WLR_DEBUG = 3, 30 WLR_LOG_IMPORTANCE_LAST, 31 }; 32 33 typedef void (*wlr_log_func_t)(enum wlr_log_importance importance, 34 const char *fmt, va_list args); 35 36 // Will log all messages less than or equal to `verbosity` 37 // If `callback` is NULL, wlr will use its default logger. 38 // The function can be called multiple times to update the verbosity or 39 // callback function. 40 void wlr_log_init(enum wlr_log_importance verbosity, wlr_log_func_t callback); 41 42 // Returns the log verbosity provided to wlr_log_init 43 enum wlr_log_importance wlr_log_get_verbosity(void); 44 45 #ifdef __GNUC__ 46 #define _WLR_ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) 47 #else 48 #define _WLR_ATTRIB_PRINTF(start, end) 49 #endif 50 51 void _wlr_log(enum wlr_log_importance verbosity, const char *format, ...) _WLR_ATTRIB_PRINTF(2, 3); 52 void _wlr_vlog(enum wlr_log_importance verbosity, const char *format, va_list args) _WLR_ATTRIB_PRINTF(2, 0); 53 54 #ifdef WLR_REL_SRC_DIR 55 // strip prefix from __FILE__, leaving the path relative to the project root 56 #define _WLR_FILENAME ((const char *)__FILE__ + sizeof(WLR_REL_SRC_DIR) - 1) 57 #else 58 #define _WLR_FILENAME __FILE__ 59 #endif 60 61 #define wlr_log(verb, fmt, ...) \ 62 _wlr_log(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__, ##__VA_ARGS__) 63 64 #define wlr_vlog(verb, fmt, args) \ 65 _wlr_vlog(verb, "[%s:%d] " fmt, _WLR_FILENAME, __LINE__, args) 66 67 #define wlr_log_errno(verb, fmt, ...) \ 68 wlr_log(verb, fmt ": %s", ##__VA_ARGS__, strerror(errno)) 69 70 #endif 71