package log

import (
	"fmt"
	"log/slog"
	"runtime"
)

func Error(err error) slog.Attr {
	return ErrorSkip(err, 2)
}

func ErrorSkip(err error, skip int) slog.Attr {
	pc, filename, line, _ := runtime.Caller(skip)

	return slog.Group("error",
		slog.String("message", err.Error()),
		slog.String("file", fmt.Sprintf("%s@%d", filename, line)),
		slog.String("func", runtime.FuncForPC(pc).Name()),
	)
}
