package util import ( "os" "runtime" "runtime/debug" "strconv" "time" "github.com/lmittmann/tint" "log/slog" ) var L *slog.Logger var LogLvl = &slog.LevelVar{} func init() { L = slog.New( tint.NewHandler(os.Stderr, &tint.Options{ Level: LogLvl, TimeFormat: time.DateTime, }), ) // buildInfo, _ := debug.ReadBuildInfo() // commit := Commit // L = L.With(slog.String("app", buildInfo.Main.Path)) // set global logger with custom options slog.SetDefault(L) } var Commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { for _, setting := range info.Settings { if setting.Key == "vcs.revision" { return setting.Value } } } return "not_available" }() // TODO clean this up func LogTraceFunc() {} func TraceFunc() string { pc, file, line, ok := runtime.Caller(1) if !ok { return "? 0 ?" } fn := runtime.FuncForPC(pc) if fn == nil { return file + " " + strconv.Itoa(line) + " ?" } return file + " " + strconv.Itoa(line) + " " + fn.Name() }