From 1423fbffdaed8b0cd38b1e0d9248567a832418f4 Mon Sep 17 00:00:00 2001 From: guoyao Date: Tue, 1 Apr 2025 15:20:05 +0800 Subject: [PATCH] log: expose wl_debug_handler for custom print debug message issue: https://gitlab.freedesktop.org/wayland/wayland/-/issues/534 Signed-off-by: guoyao --- src/connection.c | 2 +- src/wayland-client-core.h | 3 +++ src/wayland-client.c | 6 ++++++ src/wayland-private.h | 2 ++ src/wayland-server-core.h | 3 +++ src/wayland-server.c | 6 ++++++ src/wayland-util.c | 11 +++++++++++ src/wayland-util.h | 1 + 8 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/connection.c b/src/connection.c index 34495211..db1b5293 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1585,7 +1585,7 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, fprintf(f, ")\n"); if (fclose(f) == 0) { - fprintf(stderr, "%s", buffer); + wl_debug("%s", buffer); free(buffer); } } diff --git a/src/wayland-client-core.h b/src/wayland-client-core.h index 970e6254..6c4e55aa 100644 --- a/src/wayland-client-core.h +++ b/src/wayland-client-core.h @@ -312,6 +312,9 @@ wl_display_read_events(struct wl_display *display); void wl_log_set_handler_client(wl_log_func_t handler); +void +wl_debug_set_handler_client(wl_debug_func_t handler); + void wl_display_set_max_buffer_size(struct wl_display *display, size_t max_buffer_size); diff --git a/src/wayland-client.c b/src/wayland-client.c index 25aa1cd4..802ef9b1 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -2719,6 +2719,12 @@ wl_proxy_wrapper_destroy(void *proxy_wrapper) free(wrapper); } +WL_EXPORT void +wl_debug_set_handler_client(wl_debug_func_t handler) +{ + wl_debug_handler = handler; +} + WL_EXPORT void wl_log_set_handler_client(wl_log_func_t handler) { diff --git a/src/wayland-private.h b/src/wayland-private.h index fe9120af..8c9ed5bc 100644 --- a/src/wayland-private.h +++ b/src/wayland-private.h @@ -236,7 +236,9 @@ void wl_closure_destroy(struct wl_closure *closure); extern wl_log_func_t wl_log_handler; +extern wl_debug_func_t wl_debug_handler; +void wl_debug(const char *fmt, ...); void wl_log(const char *fmt, ...); void wl_abort(const char *fmt, ...); diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h index c2dcc218..dd6c261d 100644 --- a/src/wayland-server-core.h +++ b/src/wayland-server-core.h @@ -696,6 +696,9 @@ wl_shm_buffer_create(struct wl_client *client, void wl_log_set_handler_server(wl_log_func_t handler); +void +wl_debug_set_handler_server(wl_debug_func_t handler); + enum wl_protocol_logger_type { WL_PROTOCOL_LOGGER_REQUEST, WL_PROTOCOL_LOGGER_EVENT, diff --git a/src/wayland-server.c b/src/wayland-server.c index a538519e..87f24736 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -2052,6 +2052,12 @@ wl_resource_create(struct wl_client *client, return resource; } +WL_EXPORT void +wl_debug_set_handler_server(wl_debug_func_t handler) +{ + wl_debug_handler = handler; +} + WL_EXPORT void wl_log_set_handler_server(wl_log_func_t handler) { diff --git a/src/wayland-util.c b/src/wayland-util.c index 7231346b..12c3dccd 100644 --- a/src/wayland-util.c +++ b/src/wayland-util.c @@ -452,8 +452,19 @@ wl_log_stderr_handler(const char *fmt, va_list arg) vfprintf(stderr, fmt, arg); } +wl_debug_func_t wl_debug_handler = wl_log_stderr_handler; wl_log_func_t wl_log_handler = wl_log_stderr_handler; +void +wl_debug(const char *fmt, ...) +{ + va_list argp; + + va_start(argp, fmt); + wl_debug_handler(fmt, argp); + va_end(argp); +} + void wl_log(const char *fmt, ...) { diff --git a/src/wayland-util.h b/src/wayland-util.h index 4540f040..1fde75bc 100644 --- a/src/wayland-util.h +++ b/src/wayland-util.h @@ -739,6 +739,7 @@ typedef int (*wl_dispatcher_func_t)(const void *user_data, void *target, * \sa wl_log_set_handler_server */ typedef void (*wl_log_func_t)(const char *fmt, va_list args) WL_PRINTF(1, 0); +typedef wl_log_func_t wl_debug_func_t; /** * Return value of an iterator function