Skip to content

Commit

Permalink
log: refactor callsite
Browse files Browse the repository at this point in the history
Since we will use it later no with a different skip depth.
  • Loading branch information
ellemouton committed Sep 17, 2024
1 parent 98849e2 commit 7f40915
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ const calldepth = 3

// callsite returns the file name and line number of the callsite to the
// subsystem logger.
func callsite(flag uint32) (string, int) {
_, file, line, ok := runtime.Caller(calldepth)
func callsite(flag uint32, skipDepth int) (string, int) {
_, file, line, ok := runtime.Caller(skipDepth)
if !ok {
return "???", 0
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (b *Backend) print(lvl, tag string, args ...any) {
var file string
var line int
if b.flag&(Lshortfile|Llongfile) != 0 {
file, line = callsite(b.flag)
file, line = callsite(b.flag, calldepth)
}

formatHeader(bytebuf, t, lvl, tag, file, line)
Expand All @@ -231,7 +231,7 @@ func (b *Backend) printf(lvl, tag string, format string, args ...any) {
var file string
var line int
if b.flag&(Lshortfile|Llongfile) != 0 {
file, line = callsite(b.flag)
file, line = callsite(b.flag, calldepth)
}

formatHeader(bytebuf, t, lvl, tag, file, line)
Expand Down

0 comments on commit 7f40915

Please sign in to comment.