diff --git a/main.go b/main.go index c4214a1a..ad6e78fd 100644 --- a/main.go +++ b/main.go @@ -195,6 +195,9 @@ func setMainPalette(style string) { } func main() { + // Set projet's root source path. + probe.SetRoot() + app := registerApp() app.Before = registerBefore diff --git a/vendor/github.com/minio/minio-xl/pkg/probe/probe.go b/vendor/github.com/minio/minio-xl/pkg/probe/probe.go index c82df6bd..b1806958 100644 --- a/vendor/github.com/minio/minio-xl/pkg/probe/probe.go +++ b/vendor/github.com/minio/minio-xl/pkg/probe/probe.go @@ -29,6 +29,19 @@ import ( "github.com/dustin/go-humanize" ) +// Root path to the project's source. +var rootPath string + +// SetRoot sets the project's root path. Root path is automatically +// determined from the calling function's source file location. It is +// typically called from the main() function. +func SetRoot() { + // Catch the calling function's source file path. + _, file, _, _ := runtime.Caller(1) + // Save the directory alone. + rootPath = filepath.Dir(file) +} + // GetSysInfo returns useful system statistics. func GetSysInfo() map[string]string { host, err := os.Hostname() @@ -113,7 +126,7 @@ func (e *Error) trace(fields ...string) *Error { pc, file, line, _ := runtime.Caller(2) function := runtime.FuncForPC(pc).Name() _, function = filepath.Split(function) - file = "..." + strings.TrimPrefix(file, os.Getenv("GOPATH")) // trim gopathSource from file + file = strings.TrimPrefix(file, rootPath+string(os.PathSeparator)) // trims project's root path. tp := TracePoint{} if len(fields) > 0 { tp = TracePoint{Line: line, Filename: file, Function: function, Env: map[string][]string{"Tags": fields}} diff --git a/vendor/github.com/minio/minio-xl/pkg/probe/probe_test.go b/vendor/github.com/minio/minio-xl/pkg/probe/probe_test.go index 96cdc47a..594adc96 100644 --- a/vendor/github.com/minio/minio-xl/pkg/probe/probe_test.go +++ b/vendor/github.com/minio/minio-xl/pkg/probe/probe_test.go @@ -43,6 +43,8 @@ func testDummy2() *probe.Error { } func (s *MySuite) TestProbe(c *C) { + probe.SetRoot() // Set project's root source path. + es := testDummy2().Trace("TopOfStack") // Uncomment the following Println to visually test probe call trace. // fmt.Println("Expecting a simulated error here.", es)