logging: print file:line:funcName of the caller of errorIf and fatalIf (#3035)

master
Krishna Srinivas 8 years ago committed by Harshavardhana
parent 83b364891d
commit f2b0c08e34
  1. 16
      cmd/logger.go

@ -77,12 +77,26 @@ func stackInfo() string {
return strings.Replace(stackBuf.String(), filepath.ToSlash(GOPATH)+"/src/", "", -1)
}
// Get file, line, function name of the caller.
func callerLocation() string {
pc, file, line, success := runtime.Caller(2)
if !success {
file = "<unknown>"
line = 0
}
shortFile := true // We are only interested in short file form.
callerLoc := funcFromPC(pc, file, line, shortFile)
return callerLoc
}
// errorIf synonymous with fatalIf but doesn't exit on error != nil
func errorIf(err error, msg string, data ...interface{}) {
if err == nil {
return
}
location := callerLocation()
fields := logrus.Fields{
"location": location,
"cause": err.Error(),
}
if e, ok := err.(*Error); ok {
@ -97,7 +111,9 @@ func fatalIf(err error, msg string, data ...interface{}) {
if err == nil {
return
}
location := callerLocation()
fields := logrus.Fields{
"location": location,
"cause": err.Error(),
}
if globalTrace {

Loading…
Cancel
Save