Skip to content

Instantly share code, notes, and snippets.

@vikaschoudhary16
Created December 23, 2017 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikaschoudhary16/ac640cdbbb7f30bf435e8e651c5851d5 to your computer and use it in GitHub Desktop.
Save vikaschoudhary16/ac640cdbbb7f30bf435e8e651c5851d5 to your computer and use it in GitHub Desktop.
golang file_line caller prints
Add this to pkg and this print:
package resourcequota
import "path/filepath"
import "runtime"
import "fmt"
func file_line() string {
// notice that we're using 1, so it will actually log the where
// the error happened, 0 = this function, we don't want that.
pc, fn, line, _ := runtime.Caller(1)
return fmt.Sprintf("%s[%s:%d]::: ", runtime.FuncForPC(pc).Name(), filepath.Base(fn), line)
}
func caller() string {
// notice that we're using 1, so it will actually log the where
// the error happened, 0 = this function, we don't want that.
pc, fn, line, _ := runtime.Caller(2)
return fmt.Sprintf("Called From: %s[%s:%d] ", runtime.FuncForPC(pc).Name(), filepath.Base(fn), line)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment