-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Found it when using prometheus
// sourced adds a source field to the logger that contains
// the file name and line where the logging happened.
func (l logger) sourced() *logrus.Entry {
_, file, line, ok := runtime.Caller(2)
if !ok {
file = "<???>"
line = 1
} else {
slash := strings.LastIndex(file, "/")
file = file[slash+1:]
}
return l.entry.WithField("source", fmt.Sprintf("%s:%d", file, line))
}
FIXME:
- using
source
as tag would overwrite user defined value forsource
if there is any, maybe we should rename ours to_source
? but this would also add burden for log processing
TODO:
- the line number should be highlighted by IDE, so when you run test in IDE, you can click the log and jump to the line