Log relative path for caller when using `ConsoleWriter` (#267)

* use relative file path
This commit is contained in:
Jason McVetta 2020-12-29 04:38:24 +07:00 committed by GitHub
parent 29d8dac5e8
commit b7e31f4fe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
@ -367,10 +368,10 @@ func consoleDefaultFormatCaller(noColor bool) Formatter {
c = cc
}
if len(c) > 0 {
cwd, err := os.Getwd()
if err == nil {
prefix := cwd + "/"
c = strings.TrimPrefix(c, prefix)
if cwd, err := os.Getwd(); err == nil {
if rel, err := filepath.Rel(cwd, c); err == nil {
c = rel
}
}
c = colorize(c, colorBold, noColor) + colorize(" >", colorCyan, noColor)
}