log: expose wl_debug_handler for custom print debug message

issue: https://gitlab.freedesktop.org/wayland/wayland/-/issues/534
Signed-off-by: guoyao <guoyao@uniontech.com>
This commit is contained in:
guoyao 2025-04-01 15:20:05 +08:00 committed by groveer
parent 9b169ff945
commit 1423fbffda
8 changed files with 33 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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)
{

View file

@ -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, ...);

View file

@ -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,

View file

@ -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)
{

View file

@ -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, ...)
{

View file

@ -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