Skip to content

Commit

Permalink
Log relative path for caller when using ConsoleWriter (#267)
Browse files Browse the repository at this point in the history
* use relative file path
  • Loading branch information
jmcvetta authored Dec 28, 2020
1 parent 29d8dac commit b7e31f4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b7e31f4

Please sign in to comment.