mirror of
https://github.com/minio/minio.git
synced 2025-01-25 21:53:16 -05:00
filter GOPATH from stack trace (#1755)
This commit is contained in:
parent
64b0976e1b
commit
63c65b4635
@ -16,13 +16,18 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// DO NOT EDIT THIS FILE DIRECTLY. These are build-time constants
|
||||||
|
// set through ‘buildscripts/gen-ldflags.go’.
|
||||||
var (
|
var (
|
||||||
|
// minioGOPATH - GOPATH value at the time of build.
|
||||||
|
minioGOPATH = ""
|
||||||
|
|
||||||
// minioVersion - version time.RFC3339.
|
// minioVersion - version time.RFC3339.
|
||||||
minioVersion = "DEVELOPMENT.GOGET"
|
minioVersion = "DEVELOPMENT.GOGET"
|
||||||
// minioReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ.
|
// minioReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ.
|
||||||
minioReleaseTag = "DEVELOPMENT.GOGET"
|
minioReleaseTag = "DEVELOPMENT.GOGET"
|
||||||
// minioCommitID - latest commit id.
|
// minioCommitID - latest commit id.
|
||||||
minioCommitID = "DEVELOPMENT.GOGET"
|
minioCommitID = "DEVELOPMENT.GOGET"
|
||||||
// minioShortCommitID - first 12 characters from mcCommitID
|
// minioShortCommitID - first 12 characters from minioCommitID.
|
||||||
minioShortCommitID = minioCommitID[:12]
|
minioShortCommitID = minioCommitID[:12]
|
||||||
)
|
)
|
||||||
|
@ -28,10 +28,11 @@ import (
|
|||||||
|
|
||||||
func genLDFlags(version string) string {
|
func genLDFlags(version string) string {
|
||||||
var ldflagsStr string
|
var ldflagsStr string
|
||||||
ldflagsStr = "-X main.minioVersion=" + version + " "
|
ldflagsStr = "-X main.minioVersion=" + version
|
||||||
ldflagsStr = ldflagsStr + "-X main.minioReleaseTag=" + releaseTag(version) + " "
|
ldflagsStr += " -X main.minioReleaseTag=" + releaseTag(version)
|
||||||
ldflagsStr = ldflagsStr + "-X main.minioCommitID=" + commitID() + " "
|
ldflagsStr += " -X main.minioCommitID=" + commitID()
|
||||||
ldflagsStr = ldflagsStr + "-X main.minioShortCommitID=" + commitID()[:12]
|
ldflagsStr += " -X main.minioShortCommitID=" + commitID()[:12]
|
||||||
|
ldflagsStr += " -X main.minioGOPATH=" + os.Getenv("GOPATH")
|
||||||
return ldflagsStr
|
return ldflagsStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
logger.go
34
logger.go
@ -17,11 +17,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
@ -45,8 +48,8 @@ type logger struct {
|
|||||||
// Add new loggers here.
|
// Add new loggers here.
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSysInfo returns useful system statistics.
|
// sysInfo returns useful system statistics.
|
||||||
func getSysInfo() map[string]string {
|
func sysInfo() map[string]string {
|
||||||
host, err := os.Hostname()
|
host, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
host = ""
|
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
|
// errorIf synonymous with fatalIf but doesn't exit on error != nil
|
||||||
func errorIf(err error, msg string, data ...interface{}) {
|
func errorIf(err error, msg string, data ...interface{}) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sysInfo := getSysInfo()
|
sysInfo := sysInfo()
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"cause": err.Error(),
|
"cause": err.Error(),
|
||||||
"type": reflect.TypeOf(err),
|
"type": reflect.TypeOf(err),
|
||||||
"sysInfo": sysInfo,
|
"sysInfo": sysInfo,
|
||||||
}
|
}
|
||||||
if globalTrace {
|
if globalTrace {
|
||||||
stack := debug.Stack()
|
fields["stack"] = "\n" + stackInfo()
|
||||||
fields["stack"] = string(stack)
|
|
||||||
}
|
}
|
||||||
log.WithFields(fields).Errorf(msg, data...)
|
log.WithFields(fields).Errorf(msg, data...)
|
||||||
}
|
}
|
||||||
@ -89,15 +108,14 @@ func fatalIf(err error, msg string, data ...interface{}) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sysInfo := getSysInfo()
|
sysInfo := sysInfo()
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"cause": err.Error(),
|
"cause": err.Error(),
|
||||||
"type": reflect.TypeOf(err),
|
"type": reflect.TypeOf(err),
|
||||||
"sysInfo": sysInfo,
|
"sysInfo": sysInfo,
|
||||||
}
|
}
|
||||||
if globalTrace {
|
if globalTrace {
|
||||||
stack := debug.Stack()
|
fields["stack"] = "\n" + stackInfo()
|
||||||
fields["stack"] = string(stack)
|
|
||||||
}
|
}
|
||||||
log.WithFields(fields).Fatalf(msg, data...)
|
log.WithFields(fields).Fatalf(msg, data...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user