diff --git a/internal/apps/log_writer.go b/internal/apps/log_writer.go index 23bdedd..a09bf00 100644 --- a/internal/apps/log_writer.go +++ b/internal/apps/log_writer.go @@ -2,6 +2,7 @@ package apps import ( "github.com/TeaOSLab/EdgeNode/internal/goman" + "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils/sizes" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/files" @@ -77,7 +78,7 @@ func (this *LogWriter) Write(message string) { var ok bool _, file, line, ok = runtime.Caller(callDepth) if ok { - file = this.packagePath(file) + file = utils.RemoveWorkspace(this.packagePath(file)) } } diff --git a/internal/errors/error.go b/internal/errors/error.go index 74faa7d..dbea041 100644 --- a/internal/errors/error.go +++ b/internal/errors/error.go @@ -2,6 +2,7 @@ package errors import ( "errors" + "github.com/TeaOSLab/EdgeNode/internal/utils" "path/filepath" "runtime" "strconv" @@ -15,7 +16,7 @@ type errorObj struct { } func (this *errorObj) Error() string { - s := this.err.Error() + "\n " + this.file + s := this.err.Error() + "\n " + utils.RemoveWorkspace(this.file) if len(this.funcName) > 0 { s += ":" + this.funcName + "()" } @@ -23,7 +24,7 @@ func (this *errorObj) Error() string { return s } -// 新错误 +// New 新错误 func New(errText string) error { ptr, file, line, ok := runtime.Caller(1) funcName := "" @@ -39,7 +40,7 @@ func New(errText string) error { } } -// 包装已有错误 +// Wrap 包装已有错误 func Wrap(err error) error { if err == nil { return nil diff --git a/internal/utils/workspace.go b/internal/utils/workspace.go new file mode 100644 index 0000000..eeea7bf --- /dev/null +++ b/internal/utils/workspace.go @@ -0,0 +1,15 @@ +// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package utils + +import "regexp" + +var workspaceReg = regexp.MustCompile(`/Edge[A-Z]\w+/`) + +func RemoveWorkspace(path string) string { + var indexes = workspaceReg.FindAllStringIndex(path, -1) + if len(indexes) > 0 { + return path[indexes[len(indexes)-1][0]:] + } + return path +}