mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
filter GOPATH from stack trace (#1755)
This commit is contained in:
parent
64b0976e1b
commit
63c65b4635
@ -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
|
||||
}
|
||||
|
||||
|
34
logger.go
34
logger.go
@ -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…
Reference in New Issue
Block a user