Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (h *Handler) appendKV(b []byte, k string, v []byte) []byte {
b = append(b, '\n')
b = binary.LittleEndian.AppendUint64(b, uint64(len(v)))
b = append(b, v...)
b = append(b, '\n')
} else {
b = append(b, k...)
b = append(b, '=')
Expand Down
24 changes: 24 additions & 0 deletions journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ func TestReplaceGroup(t *testing.T) {
}
}

func TestMessagesWithNewlines(t *testing.T) {
buf := new(bytes.Buffer)
handler, err := NewHandler(nil)
if err != nil {
t.Fatal(err)
}
handler.w = buf

record := slog.NewRecord(time.Now(), slog.LevelInfo, "Line 1\nLine 2\nLine 3", 0)
record.AddAttrs(slog.Attr{Key: "MULTILINE_ATTR", Value: slog.StringValue("value1\nvalue2")})

_ = handler.Handle(context.TODO(), record)
kv, err := deserializeKeyValue(buf)
if err != nil {
t.Fatal(err)
}
if kv["MESSAGE"] != "Line 1\nLine 2\nLine 3" {
t.Errorf("Expected multiline message, got: %q", kv["MESSAGE"])
}
if kv["MULTILINE_ATTR"] != "value1\nvalue2" {
t.Errorf("Expected multiline attribute, got: %q", kv["MULTILINE_ATTR"])
}
}

func createNestedMap(m map[string]any, keys []string, value any) {
for i, key := range keys {
if i == len(keys)-1 {
Expand Down