From 3ec4f49b0f9d37100f5c6085b66abf20c6c0fa88 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Wed, 26 Mar 2025 17:40:57 +0100 Subject: [PATCH] observe: allow DEBUG logs via env vars --- internal/app/app.go | 4 +++- internal/testhelpers/logging.go | 7 ++++++- main.go | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 51832c8..22b250e 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -101,7 +101,7 @@ func Run(ctx context.Context, params RunParams) error { return nil } - logger.Info("Command received", "cmd", cmd.Name()) + logger.Debug("Command received", "cmd", cmd.Name()) switch c := cmd.(type) { case terminal.CommandStartDestination: mp.StartDestination(c.URL) @@ -113,9 +113,11 @@ func Run(ctx context.Context, params RunParams) error { case <-uiUpdateT.C: updateUI() case serverState := <-srv.C(): + logger.Debug("Server state received", "state", serverState) applyServerState(serverState, state) updateUI() case mpState := <-mp.C(): + logger.Debug("Multiplexer state received", "state", mpState) destErrors := applyMultiplexerState(mpState, state) for _, destError := range destErrors { diff --git a/internal/testhelpers/logging.go b/internal/testhelpers/logging.go index dfc6dc2..7d0a67c 100644 --- a/internal/testhelpers/logging.go +++ b/internal/testhelpers/logging.go @@ -12,5 +12,10 @@ func NewNopLogger() *slog.Logger { // NewTestLogger returns a logger that writes to stderr. func NewTestLogger() *slog.Logger { - return slog.New(slog.NewTextHandler(os.Stderr, nil)) + var handlerOpts slog.HandlerOptions + // RUNNER_DEBUG is used in the GitHub actions runner to enable debug logging. + if os.Getenv("DEBUG") != "" || os.Getenv("RUNNER_DEBUG") != "" { + handlerOpts.Level = slog.LevelDebug + } + return slog.New(slog.NewTextHandler(os.Stderr, &handlerOpts)) } diff --git a/main.go b/main.go index f4005c6..5789a68 100644 --- a/main.go +++ b/main.go @@ -148,5 +148,9 @@ func buildLogger(cfg config.LogFile) (*slog.Logger, error) { return nil, fmt.Errorf("error opening log file: %w", err) } - return slog.New(slog.NewTextHandler(fptr, nil)), nil + var handlerOpts slog.HandlerOptions + if os.Getenv("OCTO_DEBUG") != "" { + handlerOpts.Level = slog.LevelDebug + } + return slog.New(slog.NewTextHandler(fptr, &handlerOpts)), nil }