app/internal/log: use the app ID as the Android log tag

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í <mvdan@mvdan.cc>
This commit is contained in:
Daniel Martí
2020-05-05 23:37:16 +01:00
committed by Elias Naur
parent ec34eb4919
commit e97adeedd9
4 changed files with 8 additions and 4 deletions
+2
View File
@@ -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"
+1 -1
View File
@@ -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.
+3 -3
View File
@@ -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 {
+2
View File
@@ -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":