From e97adeedd9186530b84a40ebd0ebb7af66eb0e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 5 May 2020 23:37:16 +0100 Subject: [PATCH] app/internal/log: use the app ID as the Android log tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way, a Gio app's logs can be filtered uniquely, which wasn't possible before since the tag "gio" would be the same between gio apps. Since the app ID is supplied at build time, inject it via a variable with the linker's help. The variable is only used on Android for now, but that's OK. It might be useful for other platforms or other internal packages in the future. Fixes #84. Signed-off-by: Daniel Martí --- app/internal/log/log.go | 2 ++ app/internal/log/log_android.go | 2 +- cmd/gogio/android_test.go | 6 +++--- cmd/gogio/main.go | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/internal/log/log.go b/app/internal/log/log.go index 4d3a9ca9..731ae492 100644 --- a/app/internal/log/log.go +++ b/app/internal/log/log.go @@ -3,3 +3,5 @@ // Package points standard output, standard error and the standard // library package log to the platform logger. package log + +var appID = "gio" diff --git a/app/internal/log/log_android.go b/app/internal/log/log_android.go index 3f7d2cc1..7936911a 100644 --- a/app/internal/log/log_android.go +++ b/app/internal/log/log_android.go @@ -22,7 +22,7 @@ import ( // 1024 is the truncation limit from android/log.h, plus a \n. const logLineLimit = 1024 -var logTag = C.CString("gio") +var logTag = C.CString(appID) func init() { // Android's logcat already includes timestamps. diff --git a/cmd/gogio/android_test.go b/cmd/gogio/android_test.go index 7c8e6b4d..3c5cc00d 100644 --- a/cmd/gogio/android_test.go +++ b/cmd/gogio/android_test.go @@ -76,9 +76,9 @@ func (d *AndroidTestDriver) Start(path string) { ctx, cancel := context.WithCancel(context.Background()) cmd := exec.CommandContext(ctx, d.adbPath, "logcat", - "-s", // suppress other logs - "-T1", // don't show prevoius log messages - "gio:*", // show all logs from gio + "-s", // suppress other logs + "-T1", // don't show prevoius log messages + appid+":*", // show all logs from our gio app ID ) logcat, err := cmd.StdoutPipe() if err != nil { diff --git a/cmd/gogio/main.go b/cmd/gogio/main.go index 8dc92b70..cf0ec9c5 100644 --- a/cmd/gogio/main.go +++ b/cmd/gogio/main.go @@ -98,6 +98,8 @@ func mainErr() error { if bi.appID == "" { bi.appID = appIDFromPackage(pkgPath) } + // Pass appID along, to be used for logging on platforms like Android. + bi.ldflags = fmt.Sprintf("-X gioui.org/app/internal/log.appID=%s", bi.appID) switch *target { case "js":