mirror of
https://github.com/pgsty/minio.git
synced 2026-07-19 20:20:25 +03:00
lock/instrumentation: Cleanup and print in user friendly form. (#2807)
This commit is contained in:
+18
-1
@@ -19,6 +19,9 @@ package cmd
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
@@ -42,6 +45,20 @@ type logger struct {
|
||||
// Add new loggers here.
|
||||
}
|
||||
|
||||
// Function takes input with the results from runtime.Caller(1). Depending on the boolean.
|
||||
// This function can either returned a shotFile form or a longFile form.
|
||||
func funcFromPC(pc uintptr, file string, line int, shortFile bool) string {
|
||||
var fn, name string
|
||||
if shortFile {
|
||||
fn = strings.Replace(file, filepath.ToSlash(GOPATH)+"/src/github.com/minio/minio/cmd/", "", -1)
|
||||
name = strings.Replace(runtime.FuncForPC(pc).Name(), "github.com/minio/minio/cmd.", "", -1)
|
||||
} else {
|
||||
fn = strings.Replace(file, filepath.ToSlash(GOPATH)+"/src/", "", -1)
|
||||
name = strings.Replace(runtime.FuncForPC(pc).Name(), "github.com/minio/minio/cmd.", "", -1)
|
||||
}
|
||||
return fmt.Sprintf("%s [%s:%d]", name, fn, line)
|
||||
}
|
||||
|
||||
// stackInfo returns printable stack trace.
|
||||
func stackInfo() string {
|
||||
// Convert stack-trace bytes to io.Reader.
|
||||
@@ -56,7 +73,7 @@ func stackInfo() string {
|
||||
stackBuf.ReadFrom(rawStack)
|
||||
|
||||
// Strip GOPATH of the build system and return.
|
||||
return strings.Replace(stackBuf.String(), GOPATH+"/src/", "", -1)
|
||||
return strings.Replace(stackBuf.String(), filepath.ToSlash(GOPATH)+"/src/", "", -1)
|
||||
}
|
||||
|
||||
// errorIf synonymous with fatalIf but doesn't exit on error != nil
|
||||
|
||||
Reference in New Issue
Block a user