Skip to content

Commit 4dcde7b

Browse files
committed
Keep ReplayHandler when using With or WithGroup
1 parent ebfce49 commit 4dcde7b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

internal/workflowstate/replaylogger.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ func (rh *replayHandler) Handle(ctx context.Context, r slog.Record) error {
2424
return rh.handler.Handle(ctx, r)
2525
}
2626

27-
// WithAttrs implements slog.Handler.
2827
func (rh *replayHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
29-
return rh.handler.WithAttrs(attrs)
28+
return &replayHandler{
29+
state: rh.state,
30+
handler: rh.handler.WithAttrs(attrs),
31+
}
3032
}
3133

3234
// WithGroup implements slog.Handler.
3335
func (rh *replayHandler) WithGroup(name string) slog.Handler {
34-
return rh.handler.WithGroup(name)
36+
return &replayHandler{
37+
state: rh.state,
38+
handler: rh.handler.WithGroup(name),
39+
}
3540
}
3641

3742
var _ slog.Handler = (*replayHandler)(nil)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package workflowstate
2+
3+
import (
4+
"log/slog"
5+
"testing"
6+
7+
"github.com/benbjohnson/clock"
8+
"github.com/cschleiden/go-workflows/core"
9+
"github.com/google/uuid"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func Test_ReplayLogger_With(t *testing.T) {
14+
i := core.NewWorkflowInstance(uuid.NewString(), "")
15+
wfState := NewWorkflowState(i, slog.Default(), clock.New())
16+
17+
with := wfState.Logger().With(slog.String("foo", "bar"))
18+
require.IsType(t, &replayHandler{}, with.Handler())
19+
}
20+
21+
func Test_ReplayLogger_WithGroup(t *testing.T) {
22+
i := core.NewWorkflowInstance(uuid.NewString(), "")
23+
wfState := NewWorkflowState(i, slog.Default(), clock.New())
24+
25+
with := wfState.Logger().WithGroup("group_name")
26+
require.IsType(t, &replayHandler{}, with.Handler())
27+
}

0 commit comments

Comments
 (0)