filter GOPATH from stack trace (#1755)

master
Anand Babu (AB) Periasamy 9 years ago committed by Harshavardhana
parent 64b0976e1b
commit 63c65b4635
  1. 7
      build-constants.go
  2. 9
      buildscripts/gen-ldflags.go
  3. 34
      logger.go

@ -16,13 +16,18 @@
package main
// DO NOT EDIT THIS FILE DIRECTLY. These are build-time constants
// set through ‘buildscripts/gen-ldflags.go’.
var (
// minioGOPATH - GOPATH value at the time of build.
minioGOPATH = ""
// minioVersion - version time.RFC3339.
minioVersion = "DEVELOPMENT.GOGET"
// minioReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ.
minioReleaseTag = "DEVELOPMENT.GOGET"
// minioCommitID - latest commit id.
minioCommitID = "DEVELOPMENT.GOGET"
// minioShortCommitID - first 12 characters from mcCommitID
// minioShortCommitID - first 12 characters from minioCommitID.
minioShortCommitID = minioCommitID[:12]
)

@ -28,10 +28,11 @@ import (
func genLDFlags(version string) string {
var ldflagsStr string
ldflagsStr = "-X main.minioVersion=" + version + " "
ldflagsStr = ldflagsStr + "-X main.minioReleaseTag=" + releaseTag(version) + " "
ldflagsStr = ldflagsStr + "-X main.minioCommitID=" + commitID() + " "
ldflagsStr = ldflagsStr + "-X main.minioShortCommitID=" + commitID()[:12]
ldflagsStr = "-X main.minioVersion=" + version
ldflagsStr += " -X main.minioReleaseTag=" + releaseTag(version)
ldflagsStr += " -X main.minioCommitID=" + commitID()
ldflagsStr += " -X main.minioShortCommitID=" + commitID()[:12]
ldflagsStr += " -X main.minioGOPATH=" + os.Getenv("GOPATH")
return ldflagsStr
}

@ -17,11 +17,14 @@
package main
import (
"bufio"
"bytes"
"os"
"reflect"
"runtime"
"runtime/debug"
"strconv"
"strings"
"github.com/Sirupsen/logrus"
"github.com/dustin/go-humanize"
@ -45,8 +48,8 @@ type logger struct {
// Add new loggers here.
}
// getSysInfo returns useful system statistics.
func getSysInfo() map[string]string {
// sysInfo returns useful system statistics.
func sysInfo() map[string]string {
host, err := os.Hostname()
if err != nil {
host = ""
@ -66,20 +69,36 @@ func getSysInfo() map[string]string {
}
}
// stackInfo returns printable stack trace.
func stackInfo() string {
// Convert stack-trace bytes to io.Reader.
rawStack := bufio.NewReader(bytes.NewBuffer(debug.Stack()))
// Skip stack trace lines until our real caller.
for i := 0; i <= 4; i++ {
rawStack.ReadLine()
}
// Read the rest of useful stack trace.
stackBuf := new(bytes.Buffer)
stackBuf.ReadFrom(rawStack)
// Strip GOPATH of the build system and return.
return strings.Replace(stackBuf.String(), minioGOPATH+"/src/", "", -1)
}
// errorIf synonymous with fatalIf but doesn't exit on error != nil
func errorIf(err error, msg string, data ...interface{}) {
if err == nil {
return
}
sysInfo := getSysInfo()
sysInfo := sysInfo()
fields := logrus.Fields{
"cause": err.Error(),
"type": reflect.TypeOf(err),
"sysInfo": sysInfo,
}
if globalTrace {
stack := debug.Stack()
fields["stack"] = string(stack)
fields["stack"] = "\n" + stackInfo()
}
log.WithFields(fields).Errorf(msg, data...)
}
@ -89,15 +108,14 @@ func fatalIf(err error, msg string, data ...interface{}) {
if err == nil {
return
}
sysInfo := getSysInfo()
sysInfo := sysInfo()
fields := logrus.Fields{
"cause": err.Error(),
"type": reflect.TypeOf(err),
"sysInfo": sysInfo,
}
if globalTrace {
stack := debug.Stack()
fields["stack"] = string(stack)
fields["stack"] = "\n" + stackInfo()
}
log.WithFields(fields).Fatalf(msg, data...)
}

Loading…
Cancel
Save