Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
renathoaz opened this issue Jan 17, 2018 · 3 comments
Closed

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

renathoaz opened this issue Jan 17, 2018 · 3 comments

Comments

@renathoaz
Copy link

renathoaz commented Jan 17, 2018

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
Copy link
Owner

onrik commented Jan 18, 2018

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)
}

@onrik onrik closed this as completed Jan 18, 2018
@renathoaz
Copy link
Author

Excellent! Thank you!

@tzvatot
Copy link

tzvatot commented Apr 18, 2019

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

missing "return" for fmt.Sprintf...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants