From 49a363a15d8ce13ac3f1890aa0040ff36d2edc57 Mon Sep 17 00:00:00 2001 From: Roger Ng Date: Wed, 15 Jul 2026 14:24:31 +0000 Subject: [PATCH] Refactor hammer TUI log writer --- internal/hammer/hammer.go | 1 - internal/hammer/loadtest/tui.go | 9 +++------ internal/mirror/hammer/hammer.go | 1 - internal/mirror/hammer/loadtest/tui.go | 9 +++------ 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/internal/hammer/hammer.go b/internal/hammer/hammer.go index ad93d25d9..e6bf07acc 100644 --- a/internal/hammer/hammer.go +++ b/internal/hammer/hammer.go @@ -189,7 +189,6 @@ func main() { if *showUI { c := loadtest.NewController(hammer, ha) - slog.SetDefault(slog.New(slog.NewTextHandler(c.LogWriter(), &slog.HandlerOptions{Level: slog.Level(*slogLevel)}))) c.Run(ctx) } else { <-ctx.Done() diff --git a/internal/hammer/loadtest/tui.go b/internal/hammer/loadtest/tui.go index 2540c8d56..65fc85e9f 100644 --- a/internal/hammer/loadtest/tui.go +++ b/internal/hammer/loadtest/tui.go @@ -17,7 +17,6 @@ package loadtest import ( "context" "fmt" - "io" "strings" "time" @@ -69,6 +68,9 @@ func NewController(h *Hammer, a *HammerAnalyser) *tuiController { } func (c *tuiController) Run(ctx context.Context) { + // Redirect logs to the view. + slog.SetDefault(slog.New(slog.NewTextHandler(c.logView, &slog.HandlerOptions{Level: slog.LevelInfo}))) + go c.updateStatsLoop(ctx, 500*time.Millisecond) c.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { @@ -144,8 +146,3 @@ func (c *tuiController) updateStatsLoop(ctx context.Context, interval time.Durat } } } - -// LogWriter returns a writer that writes to the log TextView. -func (c *tuiController) LogWriter() io.Writer { - return c.logView -} diff --git a/internal/mirror/hammer/hammer.go b/internal/mirror/hammer/hammer.go index b3ac5918d..b2e8b8126 100644 --- a/internal/mirror/hammer/hammer.go +++ b/internal/mirror/hammer/hammer.go @@ -230,7 +230,6 @@ func main() { if *showUI { c := loadtest.NewController(hammer, ha) - slog.SetDefault(slog.New(slog.NewTextHandler(c.LogWriter(), &slog.HandlerOptions{Level: slog.Level(*slogLevel)}))) c.Run(ctx) } else { <-ctx.Done() diff --git a/internal/mirror/hammer/loadtest/tui.go b/internal/mirror/hammer/loadtest/tui.go index 2540c8d56..65fc85e9f 100644 --- a/internal/mirror/hammer/loadtest/tui.go +++ b/internal/mirror/hammer/loadtest/tui.go @@ -17,7 +17,6 @@ package loadtest import ( "context" "fmt" - "io" "strings" "time" @@ -69,6 +68,9 @@ func NewController(h *Hammer, a *HammerAnalyser) *tuiController { } func (c *tuiController) Run(ctx context.Context) { + // Redirect logs to the view. + slog.SetDefault(slog.New(slog.NewTextHandler(c.logView, &slog.HandlerOptions{Level: slog.LevelInfo}))) + go c.updateStatsLoop(ctx, 500*time.Millisecond) c.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { @@ -144,8 +146,3 @@ func (c *tuiController) updateStatsLoop(ctx context.Context, interval time.Durat } } } - -// LogWriter returns a writer that writes to the log TextView. -func (c *tuiController) LogWriter() io.Writer { - return c.logView -}