mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-18 12:49:07 +02:00
feat(ui): GUI debug logging follows daemon log level + debug bundle
When the daemon is set to debug/trace, the GUI now automatically writes a rotated gui-client.log in the user's config dir and the daemon's debug bundle collects it. The UI learns the level both at startup (daemon already in debug) and live, by piggybacking the existing SubscribeEvents stream: the daemon publishes a marked log-level-changed SystemEvent (and a per-subscription snapshot), which DaemonFeed routes to guilog.DebugLog instead of an OS toast. The UI registers its log path via a new RegisterUILog RPC so the root daemon, which can't resolve the user's config dir, knows where to find the file. Manual --log-file (any value) disables the daemon-driven file logging. Fix: client/ui SetLogLevel looked up proto.LogLevel_value with the lowercase logrus name, which never matched the uppercase enum keys and silently fell back to INFO — so trace/debug requests from the bundle flow had no effect.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/netbirdio/netbird/client/proto"
|
||||
"github.com/netbirdio/netbird/version"
|
||||
@@ -99,12 +100,29 @@ func (s *Debug) RevealFile(_ context.Context, path string) error {
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
// RegisterUILog tells the daemon the absolute path of the GUI's log file so
|
||||
// the daemon's debug bundle can collect it (the daemon runs as root and can't
|
||||
// resolve the user's config dir). Called by LogLevelWatcher on each daemon
|
||||
// (re)connect.
|
||||
func (s *Debug) RegisterUILog(ctx context.Context, path string) error {
|
||||
cli, err := s.conn.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = cli.RegisterUILog(ctx, &proto.RegisterUILogRequest{Path: path})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Debug) SetLogLevel(ctx context.Context, lvl LogLevel) error {
|
||||
cli, err := s.conn.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
level, ok := proto.LogLevel_value[lvl.Level]
|
||||
// proto.LogLevel_value keys are the enum names (TRACE/DEBUG/INFO/...), but
|
||||
// callers (the React side, GetLogLevel) use the lowercase logrus names
|
||||
// ("trace"/"debug"/...). Upper-case before the lookup so a lowercase level
|
||||
// doesn't silently fall back to INFO.
|
||||
level, ok := proto.LogLevel_value[strings.ToUpper(lvl.Level)]
|
||||
if !ok {
|
||||
level = int32(proto.LogLevel_INFO)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user