Skip to content

Commit 49a363a

Browse files
committed
Refactor hammer TUI log writer
1 parent 6d22714 commit 49a363a

4 files changed

Lines changed: 6 additions & 14 deletions

File tree

internal/hammer/hammer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ func main() {
189189

190190
if *showUI {
191191
c := loadtest.NewController(hammer, ha)
192-
slog.SetDefault(slog.New(slog.NewTextHandler(c.LogWriter(), &slog.HandlerOptions{Level: slog.Level(*slogLevel)})))
193192
c.Run(ctx)
194193
} else {
195194
<-ctx.Done()

internal/hammer/loadtest/tui.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package loadtest
1717
import (
1818
"context"
1919
"fmt"
20-
"io"
2120
"strings"
2221
"time"
2322

@@ -69,6 +68,9 @@ func NewController(h *Hammer, a *HammerAnalyser) *tuiController {
6968
}
7069

7170
func (c *tuiController) Run(ctx context.Context) {
71+
// Redirect logs to the view.
72+
slog.SetDefault(slog.New(slog.NewTextHandler(c.logView, &slog.HandlerOptions{Level: slog.LevelInfo})))
73+
7274
go c.updateStatsLoop(ctx, 500*time.Millisecond)
7375

7476
c.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
@@ -144,8 +146,3 @@ func (c *tuiController) updateStatsLoop(ctx context.Context, interval time.Durat
144146
}
145147
}
146148
}
147-
148-
// LogWriter returns a writer that writes to the log TextView.
149-
func (c *tuiController) LogWriter() io.Writer {
150-
return c.logView
151-
}

internal/mirror/hammer/hammer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ func main() {
230230

231231
if *showUI {
232232
c := loadtest.NewController(hammer, ha)
233-
slog.SetDefault(slog.New(slog.NewTextHandler(c.LogWriter(), &slog.HandlerOptions{Level: slog.Level(*slogLevel)})))
234233
c.Run(ctx)
235234
} else {
236235
<-ctx.Done()

internal/mirror/hammer/loadtest/tui.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package loadtest
1717
import (
1818
"context"
1919
"fmt"
20-
"io"
2120
"strings"
2221
"time"
2322

@@ -69,6 +68,9 @@ func NewController(h *Hammer, a *HammerAnalyser) *tuiController {
6968
}
7069

7170
func (c *tuiController) Run(ctx context.Context) {
71+
// Redirect logs to the view.
72+
slog.SetDefault(slog.New(slog.NewTextHandler(c.logView, &slog.HandlerOptions{Level: slog.LevelInfo})))
73+
7274
go c.updateStatsLoop(ctx, 500*time.Millisecond)
7375

7476
c.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
@@ -144,8 +146,3 @@ func (c *tuiController) updateStatsLoop(ctx context.Context, interval time.Durat
144146
}
145147
}
146148
}
147-
148-
// LogWriter returns a writer that writes to the log TextView.
149-
func (c *tuiController) LogWriter() io.Writer {
150-
return c.logView
151-
}

0 commit comments

Comments
 (0)