libweston: Enable logging for libseat launcher

The built-in backend of libseat requires users to enable a logging
level in order for libseat to start writing out log messages.  For that
to happen we split out the info and error log level messages into the
compositor's log scope, while debug level messages go into a dedicated
scope.

With that, this patch brings in a new scope, called libseat-debug, which
users need to explicity create a subscription for it as to retrieve/have
access to debug message coming out of libseat. Note that by default we
have a subscription for the log-scope so any errors/info from libseat
would be displayed to the user.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
Marius Vlad 2022-03-09 12:06:33 +02:00
parent e9fe66a91c
commit c19cf3d684
3 changed files with 64 additions and 0 deletions

View File

@ -1166,6 +1166,7 @@ struct weston_compositor {
struct weston_log_context *weston_log_ctx;
struct weston_log_scope *debug_scene;
struct weston_log_scope *timeline;
struct weston_log_scope *libseat_debug;
struct content_protection *content_protection;
};

View File

@ -7834,6 +7834,10 @@ weston_compositor_create(struct wl_display *display,
weston_timeline_create_subscription,
weston_timeline_destroy_subscription,
ec);
ec->libseat_debug =
weston_compositor_add_log_scope(ec, "libseat-debug",
"libseat debug messages\n",
NULL, NULL, NULL);
return ec;
fail:
@ -8215,6 +8219,9 @@ weston_compositor_destroy(struct weston_compositor *compositor)
weston_log_scope_destroy(compositor->timeline);
compositor->timeline = NULL;
weston_log_scope_destroy(compositor->libseat_debug);
compositor->libseat_debug = NULL;
if (compositor->default_dmabuf_feedback) {
weston_dmabuf_feedback_destroy(compositor->default_dmabuf_feedback);
weston_dmabuf_feedback_format_table_destroy(compositor->dmabuf_feedback_format_table);

View File

@ -32,6 +32,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@ -40,6 +41,8 @@
#include <libseat.h>
#include <libweston/libweston.h>
#include <libweston/weston-log.h>
#include "weston-log-internal.h"
#include "backend.h"
#include "dbus.h"
#include "launcher-impl.h"
@ -60,6 +63,11 @@ struct launcher_libseat {
struct wl_list devices;
};
/* debug messages go into a dedicated libseat-debug scope, while info and err
* log level messages go into the log_scope, which the compositor has a
* subscription by default*/
static struct weston_log_scope *libseat_debug_scope = NULL;
static struct launcher_libseat_device *
find_device_by_fd(struct launcher_libseat *wl, int fd)
{
@ -179,6 +187,44 @@ libseat_event(int fd, uint32_t mask, void *data)
return 1;
}
static void
log_libseat_info_err(const char *fmt, va_list ap)
{
/* these all have been set-up by the compositor and use the 'log' scope */
weston_vlog(fmt, ap);
weston_log_continue("\n");
}
static void
log_libseat_debug(const char *fmt, va_list ap)
{
int len_va;
char *str;
const char *oom = "Out of memory";
if (!weston_log_scope_is_enabled(libseat_debug_scope))
return;
len_va = vasprintf(&str, fmt, ap);
if (len_va >= 0) {
weston_log_scope_printf(libseat_debug_scope, "%s\n", str);
free(str);
} else {
weston_log_scope_printf(libseat_debug_scope, "%s\n", oom);
}
}
static void log_libseat(enum libseat_log_level level,
const char *fmt, va_list ap)
{
if (level == LIBSEAT_LOG_LEVEL_DEBUG) {
log_libseat_debug(fmt, ap);
return;
}
log_libseat_info_err(fmt, ap);
}
static int
seat_open(struct weston_launcher **out, struct weston_compositor *compositor,
const char *seat_id, bool sync_drm)
@ -195,6 +241,13 @@ seat_open(struct weston_launcher **out, struct weston_compositor *compositor,
wl->compositor = compositor;
wl_list_init(&wl->devices);
libseat_debug_scope = compositor->libseat_debug;
assert(libseat_debug_scope);
libseat_set_log_handler(log_libseat);
/* includes (all) other log levels available <= LOG_LEVEL_DEBUG */
libseat_set_log_level(LIBSEAT_LOG_LEVEL_DEBUG);
wl->seat = libseat_open_seat(&seat_listener, wl);
if (wl->seat == NULL) {
weston_log("libseat: could not open seat\n");
@ -231,6 +284,9 @@ seat_close(struct weston_launcher *launcher)
{
struct launcher_libseat *wl = wl_container_of(launcher, wl, base);
libseat_debug_scope = NULL;
libseat_set_log_handler(NULL);
if (wl->seat != NULL) {
libseat_close_seat(wl->seat);
}