Skip to content

Commit 6a45b1e

Browse files
committed
log: log fn name of the immediate log caller
1 parent 9039779 commit 6a45b1e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

intra/log/logger.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const qSize = 512
208208
const minQSize = 16
209209

210210
// consoleChSize is the size of the console channel.
211-
const consoleChSize = 512
211+
const consoleChSize = 1024
212212

213213
// minBytesForFullStacktrace is the size needed for a full stacktrace.
214214
const minBytesForFullStacktrace = 16 << 10 // 16KB
@@ -605,20 +605,22 @@ func callers(at, until int, sep1, sep2 string) (pcs []uintptr, files []string, s
605605
file := frame.File
606606
line := frame.Line
607607
fn := frame.Function
608+
if len(file) <= 0 { // more is false when file is empty
609+
file = fileunknown
610+
} else {
611+
file = shortfile(file) + sep1 + fmt.Sprint(line)
612+
}
608613
if len(fn) <= 0 {
609614
fn = callerunknown
610615
} else {
611616
// ex: fn = "github.com/celzero/firestack/intra/dnsx.ChooseHealthyProxyHostPort"
612617
fn = shortfile(fn)
613618
}
614-
if len(file) <= 0 { // more is false when file is empty
615-
file = fileunknown
616-
} else {
617-
file = shortfile(file) + sep1 + fmt.Sprint(line) + sep2 + fn
618-
}
619+
620+
file += sep2 + fn
619621
pcs = append(pcs, pc)
620622
files = append(files, file)
621-
if !more || file == fileunknown || fn == callerunknown {
623+
if !more {
622624
break
623625
}
624626
skipped = until - i
@@ -627,7 +629,7 @@ func callers(at, until int, sep1, sep2 string) (pcs []uintptr, files []string, s
627629
}
628630

629631
func tracecaller(s string) bool {
630-
if len(s) <= 0 || s == callerunknown || s == fileunknown {
632+
if len(s) <= 0 || (strings.HasSuffix(s, callerunknown) && strings.HasPrefix(s, fileunknown)) {
631633
return false
632634
}
633635
// ex: asm_arm64.s:1223>async.go:49>async.go:121>proxy.go:789
@@ -702,8 +704,8 @@ func (l *simpleLogger) writelog(lvl LogLevel, at int, msg string, args ...any) {
702704
}
703705
fallthrough
704706
default:
705-
if tracecaller(file1) { // same as x[0]
706-
trace += file1
707+
if tracecaller(x[0]) { // x[0] == file1 without fn info
708+
trace += x[0]
707709
}
708710
if len(trace) > 0 {
709711
trace += ": " // end-of-trace marker

0 commit comments

Comments
 (0)