Skip to content

Commit 1419ab6

Browse files
committed
Add option to uppercase things
1 parent 5e707dd commit 1419ab6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

journal_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,34 @@ func TestReplaceAttr(t *testing.T) {
175175
}
176176
}
177177

178+
func TestReplaceGroup(t *testing.T) {
179+
buf := new(bytes.Buffer)
180+
handler, err := NewHandler(&Options{
181+
ReplaceGroup: func(group string) string {
182+
return strings.ToUpper(group)
183+
},
184+
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
185+
a.Key = strings.ToUpper(a.Key)
186+
return a
187+
}})
188+
189+
if err != nil {
190+
t.Fatal(err)
191+
}
192+
handler.w = buf
193+
record := slog.NewRecord(time.Now(), slog.LevelInfo, "Hello, World!", 0)
194+
record.AddAttrs(slog.Group("group", slog.Attr{Key: "key", Value: slog.StringValue("value")}))
195+
196+
_ = handler.Handle(context.TODO(), record)
197+
kv, err := deserializeKeyValue(buf)
198+
if err != nil {
199+
t.Fatal(err)
200+
}
201+
if kv["GROUP_KEY"] != "value" {
202+
t.Error("Unexpected attribute", kv)
203+
}
204+
}
205+
178206
func createNestedMap(m map[string]any, keys []string, value any) {
179207
for i, key := range keys {
180208
if i == len(keys)-1 {

0 commit comments

Comments
 (0)