From 1d792f0b532ea96b926c166e77fe345cdd512b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Tue, 14 Apr 2026 18:50:25 +0200 Subject: [PATCH] Add logcat log collection for Android debug bundles Move log collection into platform-dispatched addPlatformLog(): - Android: dumps logcat buffer via /system/bin/logcat -d - Other platforms: existing file-based log + systemd fallback --- client/internal/debug/debug.go | 13 ++------- client/internal/debug/debug_android.go | 34 +++++++++++++++++++++++ client/internal/debug/debug_nonandroid.go | 25 +++++++++++++++++ 3 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 client/internal/debug/debug_android.go create mode 100644 client/internal/debug/debug_nonandroid.go diff --git a/client/internal/debug/debug.go b/client/internal/debug/debug.go index 596ac58ce..bddb9a69e 100644 --- a/client/internal/debug/debug.go +++ b/client/internal/debug/debug.go @@ -16,7 +16,6 @@ import ( "path/filepath" "runtime" "runtime/pprof" - "slices" "sort" "strings" "time" @@ -31,7 +30,6 @@ import ( "github.com/netbirdio/netbird/client/internal/updater/installer" nbstatus "github.com/netbirdio/netbird/client/status" mgmProto "github.com/netbirdio/netbird/shared/management/proto" - "github.com/netbirdio/netbird/util" ) const readmeContent = `Netbird debug bundle @@ -376,15 +374,8 @@ func (g *BundleGenerator) createArchive() error { log.Errorf("failed to add wg show output: %v", err) } - if g.logPath != "" && !slices.Contains(util.SpecialLogs, g.logPath) { - if err := g.addLogfile(); err != nil { - log.Errorf("failed to add log file to debug bundle: %v", err) - if err := g.trySystemdLogFallback(); err != nil { - log.Errorf("failed to add systemd logs as fallback: %v", err) - } - } - } else if err := g.trySystemdLogFallback(); err != nil { - log.Errorf("failed to add systemd logs: %v", err) + if err := g.addPlatformLog(); err != nil { + log.Errorf("failed to add logs to debug bundle: %v", err) } if err := g.addUpdateLogs(); err != nil { diff --git a/client/internal/debug/debug_android.go b/client/internal/debug/debug_android.go new file mode 100644 index 000000000..398e40872 --- /dev/null +++ b/client/internal/debug/debug_android.go @@ -0,0 +1,34 @@ +//go:build android + +package debug + +import ( + "fmt" + "os/exec" + "strings" + + log "github.com/sirupsen/logrus" +) + +func (g *BundleGenerator) addPlatformLog() error { + cmd := exec.Command("/system/bin/logcat", "-d") + out, err := cmd.Output() + if err != nil { + return fmt.Errorf("run logcat: %w", err) + } + + var logReader *strings.Reader + if g.anonymize { + anonymized := g.anonymizer.AnonymizeString(string(out)) + logReader = strings.NewReader(anonymized) + } else { + logReader = strings.NewReader(string(out)) + } + + if err := g.addFileToZip(logReader, "logcat.txt"); err != nil { + return fmt.Errorf("add logcat to zip: %w", err) + } + + log.Debugf("added logcat output to debug bundle (%d bytes)", len(out)) + return nil +} diff --git a/client/internal/debug/debug_nonandroid.go b/client/internal/debug/debug_nonandroid.go new file mode 100644 index 000000000..117238dec --- /dev/null +++ b/client/internal/debug/debug_nonandroid.go @@ -0,0 +1,25 @@ +//go:build !android + +package debug + +import ( + "slices" + + log "github.com/sirupsen/logrus" + + "github.com/netbirdio/netbird/util" +) + +func (g *BundleGenerator) addPlatformLog() error { + if g.logPath != "" && !slices.Contains(util.SpecialLogs, g.logPath) { + if err := g.addLogfile(); err != nil { + log.Errorf("failed to add log file to debug bundle: %v", err) + if err := g.trySystemdLogFallback(); err != nil { + return err + } + } + } else if err := g.trySystemdLogFallback(); err != nil { + return err + } + return nil +}