From 47d4b43f1a63ca83b7f2dd8bc7eb24f194ebb32f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 27 Aug 2020 15:56:14 +0000 Subject: Introduce libseat_set_log_handler This allows libseat users to register a custom logging function. --- include/libseat.h | 25 +++++++++++++++++++++++++ include/log.h | 10 ++-------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/libseat.h b/include/libseat.h index ba8a1ac..be19c43 100644 --- a/include/libseat.h +++ b/include/libseat.h @@ -135,4 +135,29 @@ int libseat_get_fd(struct libseat *seat); */ int libseat_dispatch(struct libseat *seat, int timeout); +/* + * A log level. + */ +enum libseat_log_level { + LIBSEAT_LOG_LEVEL_SILENT = 0, + LIBSEAT_LOG_LEVEL_ERROR = 1, + LIBSEAT_LOG_LEVEL_INFO = 2, + LIBSEAT_LOG_LEVEL_DEBUG = 3, + LIBSEAT_LOG_LEVEL_LAST, +}; + +/* + * A function that handles log messages. + */ +typedef void (*libseat_log_func)(enum libseat_log_level level, const char *format, va_list args); + +/* + * Sets the handler for log messages. + * + * The handler will be called for each message whose level is lower or equal + * to the current log level. If the handler is NULL, the handler is reset to + * the default. + */ +void libseat_set_log_handler(libseat_log_func handler); + #endif diff --git a/include/log.h b/include/log.h index ff354f8..d4bfd89 100644 --- a/include/log.h +++ b/include/log.h @@ -3,6 +3,8 @@ #include +#include "libseat.h" + #ifdef __GNUC__ #define ATTRIB_PRINTF(start, end) __attribute__((format(printf, start, end))) #else @@ -41,14 +43,6 @@ #define log_debug(str) #endif -enum libseat_log_level { - LIBSEAT_LOG_LEVEL_SILENT = 0, - LIBSEAT_LOG_LEVEL_ERROR = 1, - LIBSEAT_LOG_LEVEL_INFO = 2, - LIBSEAT_LOG_LEVEL_DEBUG = 3, - LIBSEAT_LOG_LEVEL_LAST, -}; - void log_init(enum libseat_log_level level); void _logf(enum libseat_log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3); -- cgit v1.2.3