Skip to content

Instantly share code, notes, and snippets.

@dnozay
Created April 14, 2019 16:15
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 dnozay/78a1ef745e4835235be373e4c2a8f107 to your computer and use it in GitHub Desktop.
Save dnozay/78a1ef745e4835235be373e4c2a8f107 to your computer and use it in GitHub Desktop.
// LogNow logs the information right away.
// This is particularly useful for debugging information in case of a
// panic, or because (*testing.T) Log() output is buffered and rolled
// up with its parent test output.
func LogNow(t *testing.T, format string, args ...interface{}) {
_, file, line, ok := runtime.Caller(1)
if ok {
if file != "" {
// Truncate file name
if index := strings.LastIndex(file, "/"); index >= 0 {
file = file[index+1:]
}
}
} else {
file = "?"
line = 0
}
m := fmt.Sprintf(format, args...)
fmt.Fprintf(os.Stdout, ">>> %s [%s:%d] %s", t.Name(), file, line, m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment