zen/core/zlog/source.go

29 lines
508 B
Go

package zlog
import (
"log/slog"
"os"
"strings"
)
type slogSource struct {
*slog.Source
}
func (sl slogSource) LogValue() slog.Value {
wd, _ := os.Getwd()
file, found := strings.CutPrefix(sl.File, wd)
if found {
file = strings.TrimPrefix(file, string(os.PathSeparator))
}
split := strings.Split(sl.Function, string(os.PathSeparator))
function := split[len(split)-1]
return slog.GroupValue(
slog.String("file", file),
slog.Int("line", sl.Line),
slog.String("function", function),
)
}