onrik / logrus

Hooks for logrus logging
MIT License
122 stars 30 forks source link

Would be nice if we have option to get function name #3

Closed renathoaz closed 6 years ago

renathoaz commented 6 years ago

Would be nice if the hook has the option do display function name, just something like that could help:

        pc := make([]uintptr, 15)
    n := runtime.Callers(8, pc)
    frames := runtime.CallersFrames(pc[:n])
    frame, _ := frames.Next()
    return fmt.Sprintf("%s:%d - %s", frame.File, frame.Line, frame.Function)
onrik commented 6 years ago

I implemented function name logging. You can customize output:

hook := filename.NewHook()
hook.Formatter = func(file, function string, line int) string {
  fmt.Sprintf("%s:%d - %s", file, line, function)
}
renathoaz commented 6 years ago

Excellent! Thank you!

tzvatot commented 5 years ago
func(file, function string, line int) string {
  fmt.Sprintf("%s:%d - %s", file, line, function)
}

missing "return" for fmt.Sprintf...