[PATCH weston 4/8] compositor: offer logs via weston-debug

Maniraj Devadoss external.mdevadoss at de.adit-jv.com
Thu Aug 24 14:16:18 UTC 2017


This registers a new weston-debug scope "log" through which one can get
live log output interspersed with possible other debugging prints.

Signed-off-by: Pekka Paalanen <pq at iki.fi>
Signed-off-by: Maniraj Devadoss <external.mdevadoss at de.adit-jv.com>
---
 compositor/main.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/compositor/main.c b/compositor/main.c
index 8480fab..4b7ab6f 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -82,6 +82,7 @@ struct wet_compositor {
 };
 
 static FILE *weston_logfile = NULL;
+static struct weston_debug_scope *log_scope;
 
 static int cached_tm_mday = -1;
 
@@ -112,9 +113,17 @@ static int weston_log_timestamp(void)
 static void
 custom_handler(const char *fmt, va_list arg)
 {
+	char timestr[128];
+
 	weston_log_timestamp();
 	fprintf(weston_logfile, "libwayland: ");
 	vfprintf(weston_logfile, fmt, arg);
+
+	weston_debug_scope_timestamp(log_scope,
+				     timestr, sizeof timestr);
+	weston_debug_scope_printf(log_scope, "%s libwayland: ",
+				  timestr);
+	weston_debug_scope_vprintf(log_scope, fmt, arg);
 }
 
 static void
@@ -146,6 +155,14 @@ static int
 vlog(const char *fmt, va_list ap)
 {
 	int l;
+	char timestr[128];
+
+	if (weston_debug_scope_is_enabled(log_scope)) {
+		weston_debug_scope_timestamp(log_scope,
+					     timestr, sizeof timestr);
+		weston_debug_scope_printf(log_scope, "%s ", timestr);
+		weston_debug_scope_vprintf(log_scope, fmt, ap);
+	}
 
 	l = weston_log_timestamp();
 	l += vfprintf(weston_logfile, fmt, ap);
@@ -156,6 +173,8 @@ vlog(const char *fmt, va_list ap)
 static int
 vlog_continue(const char *fmt, va_list argp)
 {
+	weston_debug_scope_vprintf(log_scope, fmt, argp);
+
 	return vfprintf(weston_logfile, fmt, argp);
 }
 
@@ -646,6 +665,9 @@ static int on_term_signal(int signal_number, void *data)
 static void
 on_caught_signal(int s, siginfo_t *siginfo, void *context)
 {
+	/* Leak it, try to avoid more fallout. */
+	log_scope = NULL;
+
 	/* This signal handler will do a best-effort backtrace, and
 	 * then call the backend restore function, which will switch
 	 * back to the vt we launched from or ungrab X etc and then
@@ -1875,6 +1897,9 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
+	log_scope = weston_compositor_add_debug_scope(ec, "log",
+			"Weston and Wayland log\n", NULL, NULL);
+
 	if (debug_protocol)
 		weston_compositor_enable_debug_protocol(ec);
 
@@ -1986,6 +2011,7 @@ out:
 	/* free(NULL) is valid, and it won't be NULL if it's used */
 	free(user_data.parsed_options);
 
+	weston_debug_scope_destroy(log_scope);
 	weston_compositor_destroy(ec);
 
 out_signals:
-- 
2.7.4



More information about the wayland-devel mailing list