Created
April 14, 2019 16:15
-
-
Save dnozay/78a1ef745e4835235be373e4c2a8f107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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