log: added log.source config option
This commit is contained in:
parent
1ce878fdfb
commit
e45e0c0d2b
|
@ -31,6 +31,7 @@ var DefaultConfig = Entries{
|
|||
{"log.file.enable", true, "Enable file logging", false},
|
||||
{"log.level", "info", `Log level. Possible values: "debug", "info", "warn", "error"`, false},
|
||||
{"log.output", "stderr", "Log output. Possible values: \"stdout\", \"stderr\"", false},
|
||||
{"log.source", true, "Whether to add file location to logs", false},
|
||||
|
||||
{"db.driver", "sqlite3", "Database driver", false},
|
||||
{"db.path", path.Join(xdg.Home, ".local", "share", "bluemage", "data.db"), "Database path", false},
|
||||
|
|
|
@ -144,10 +144,13 @@ func (pr *PrettyHandler) Handle(ctx context.Context, record slog.Record) error {
|
|||
|
||||
if record.PC != 0 && pr.opts.AddSource {
|
||||
frame := caller.From(record.PC).Frame
|
||||
levelColor.Fprint(buf, frame.File)
|
||||
cwd, _ := os.Getwd()
|
||||
f := strings.TrimPrefix(frame.File, cwd)
|
||||
f = strings.TrimPrefix(f, string(os.PathSeparator))
|
||||
levelColor.Fprint(buf, f)
|
||||
levelColor.Fprint(buf, ":")
|
||||
levelColor.Fprint(buf, frame.Line)
|
||||
levelColor.Fprint(buf, " -- ")
|
||||
levelColor.Fprint(buf, " :: ")
|
||||
split := strings.Split(frame.Function, string(os.PathSeparator))
|
||||
fnName := split[len(split)-1]
|
||||
levelColor.Fprint(buf, fnName)
|
||||
|
|
Loading…
Reference in a new issue