~kennylevinsen/seatd-devel

seatd: Set log level when opening seats v1 REJECTED

Marius Vlad: 1
 seatd: Set log level when opening seats

 5 files changed, 28 insertions(+), 9 deletions(-)
> On Sun, Mar 6 2022 at 12:53:24 PM +0200, Marius Vlad
> <marius.vlad@collabora.com> wrote:
> > As no log level is set up there's no way to get debug messages related
> > to opening as seat.
> 
> I assume this is discovered in weston? If so, it looks like weston just
> lacks the call to libseat_set_loglevel. See the relevant bit in wlroots: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/backend/session/session.c#L75-82.
Oh, this explains why there wasn't any log level set-up in the first
place.

And I see there's also a way to set up a log handler as well. Cool, I'll
do it weston. Thanks a lot!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/seatd-devel/patches/30039/mbox | git am -3
Learn more about email & git

[PATCH] seatd: Set log level when opening seats Export this patch

As no log level is set up there's no way to get debug messages related
to opening as seat. This patch adds a helper which is used when starting
up the daemon and when opening a seat. It adds a new invalid loglevel
returned by default if none of accepted log levels are set.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
---
 common/log.c      | 17 +++++++++++++++++
 include/libseat.h |  1 +
 include/log.h     |  1 +
 libseat/libseat.c |  7 +++++++
 seatd/seatd.c     | 11 ++---------
 5 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/common/log.c b/common/log.c
index bea683b..c9aa6a1 100644
--- a/common/log.c
+++ b/common/log.c
@@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

@@ -96,3 +97,19 @@ void libseat_set_log_handler(libseat_log_func handler) {
void libseat_set_log_level(enum libseat_log_level level) {
	current_log_level = level;
}

enum libseat_log_level libseat_to_log_level(const char *log_lvl) {
	enum libseat_log_level lvl = LIBSEAT_LOG_LEVEL_INVALID;

	if (strcmp(log_lvl, "debug") == 0) {
		lvl = LIBSEAT_LOG_LEVEL_DEBUG;
	} else if (strcmp(log_lvl, "info") == 0) {
		lvl = LIBSEAT_LOG_LEVEL_INFO;
	} else if (strcmp(log_lvl, "error") == 0) {
		lvl = LIBSEAT_LOG_LEVEL_ERROR;
	} else if (strcmp(log_lvl, "silent") == 0) {
		lvl = LIBSEAT_LOG_LEVEL_SILENT;
	}

	return lvl;
}
diff --git a/include/libseat.h b/include/libseat.h
index 385acd9..33941e6 100644
--- a/include/libseat.h
+++ b/include/libseat.h
@@ -143,6 +143,7 @@ int libseat_dispatch(struct libseat *seat, int timeout);
 * A log level.
 */
enum libseat_log_level {
	LIBSEAT_LOG_LEVEL_INVALID = -1,
	LIBSEAT_LOG_LEVEL_SILENT = 0,
	LIBSEAT_LOG_LEVEL_ERROR = 1,
	LIBSEAT_LOG_LEVEL_INFO = 2,
diff --git a/include/log.h b/include/log.h
index 4cf5af3..e4a229c 100644
--- a/include/log.h
+++ b/include/log.h
@@ -34,5 +34,6 @@

void log_init(void);
void _logf(enum libseat_log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3);
enum libseat_log_level libseat_to_log_level(const char *log_lvl);

#endif
diff --git a/libseat/libseat.c b/libseat/libseat.c
index 8cc9ab2..b18b8a4 100644
--- a/libseat/libseat.c
+++ b/libseat/libseat.c
@@ -35,12 +35,19 @@ static const struct named_backend impls[] = {
#endif

struct libseat *libseat_open_seat(const struct libseat_seat_listener *listener, void *data) {
	enum libseat_log_level level = LIBSEAT_LOG_LEVEL_INVALID;
	const char *log_lvl = NULL;
	if (listener == NULL || listener->enable_seat == NULL || listener->disable_seat == NULL) {
		errno = EINVAL;
		return NULL;
	}

	log_init();
	log_lvl = getenv("SEATD_LOGLEVEL");
	if (log_lvl)
		level = libseat_to_log_level(log_lvl);
	if (level != LIBSEAT_LOG_LEVEL_INVALID)
		libseat_set_log_level(level);

	char *backend_type = getenv("LIBSEAT_BACKEND");
	if (backend_type != NULL) {
diff --git a/seatd/seatd.c b/seatd/seatd.c
index f88e6c9..652595a 100644
--- a/seatd/seatd.c
+++ b/seatd/seatd.c
@@ -111,15 +111,8 @@ int main(int argc, char *argv[]) {
			break;
		}
		case 'l':
			if (strcmp(optarg, "debug") == 0) {
				level = LIBSEAT_LOG_LEVEL_DEBUG;
			} else if (strcmp(optarg, "info") == 0) {
				level = LIBSEAT_LOG_LEVEL_INFO;
			} else if (strcmp(optarg, "error") == 0) {
				level = LIBSEAT_LOG_LEVEL_ERROR;
			} else if (strcmp(optarg, "silent") == 0) {
				level = LIBSEAT_LOG_LEVEL_SILENT;
			} else {
			level = libseat_to_log_level(optarg);
			if (level == LIBSEAT_LOG_LEVEL_INVALID) {
				fprintf(stderr, "Invalid loglevel: %s\n", optarg);
				return 1;
			}
-- 
2.34.1
> As no log level is set up there's no way to get debug messages related
> to opening as seat.
I assume this is discovered in weston? If so, it looks like weston just 
lacks the call to libseat_set_loglevel. See the relevant bit in 
wlroots: 
https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/backend/session/session.c#L75-82.