Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Re-add message
  • Loading branch information
ammario committed May 8, 2023
commit cb746033dd15b43d4cb8c503ddec7bb5d81fbdbc
16 changes: 13 additions & 3 deletions internal/entryhuman/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,26 @@ func render(w io.Writer, st lipgloss.Style, s string) string {
return s
}

func reset(w io.Writer, termW io.Writer) {
if shouldColor(termW) {
fmt.Fprintf(w, termenv.CSI+termenv.ResetSeq+"m")
}
}

// Fmt returns a human readable format for ent.
//
// We never return with a trailing newline because Go's testing framework adds one
// automatically and if we include one, then we'll get two newlines.
// We also do not indent the fields as go's test does that automatically
// for extra lines in a log so if we did it here, the fields would be indented
// twice in test logs. So the Stderr logger indents all the fields itself.
func Fmt(buf io.StringWriter, termW io.Writer, ent slog.SinkEntry,
func Fmt(
buf interface {
io.StringWriter
io.Writer
}, termW io.Writer, ent slog.SinkEntry,
) {
reset(buf, termW)
ts := ent.Time.Format(TimeFormat)
buf.WriteString(ts + " ")

Expand All @@ -83,9 +94,8 @@ func Fmt(buf io.StringWriter, termW io.Writer, ent slog.SinkEntry,
multilineVal = msg
msg = "..."
msg = quote(msg)
buf.WriteString(msg)

}
buf.WriteString(msg)

if ent.SpanContext != (trace.SpanContext{}) {
ent.Fields = append(slog.M(
Expand Down
2 changes: 1 addition & 1 deletion internal/entryhuman/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func BenchmarkFmt(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
entryhuman.Fmt(io.Discard.(io.StringWriter), w, se)
entryhuman.Fmt(bytes.NewBuffer(nil), w, se)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/entryhuman/testdata/multilineField.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
0001-01-01 00:00:00.000 [INFO] ...
0001-01-01 00:00:00.000 [INFO] msg ...
field= line1
line2
2 changes: 1 addition & 1 deletion internal/entryhuman/testdata/simpleNoFields.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2000-02-05 04:04:04.000 [DEBU]
2000-02-05 04:04:04.000 [DEBU] wowowow izi