Skip to content

Commit

Permalink
trim path for slog function
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Sep 9, 2024
1 parent 29412f8 commit f8028b0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log/slog"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -220,6 +221,9 @@ func (h *slogJSONHandler) Handle(_ context.Context, r slog.Record) error {
e.buf = append(e.buf, ',', '"')
e.buf = append(e.buf, slog.SourceKey...)
e.buf = append(e.buf, `":{"function":"`...)
if i := strings.LastIndexByte(name, '/'); i > 0 {
name = name[i+1:]
}
e.buf = append(e.buf, name...)
e.buf = append(e.buf, `","file":"`...)
e.buf = append(e.buf, file...)
Expand Down

0 comments on commit f8028b0

Please sign in to comment.