Skip to content

Commit 4bfe78d

Browse files
committed
log: incr console size, thread-safe spam counters
1 parent 5a2dea4 commit 4bfe78d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

intra/log/log.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ type conMsg struct {
5353
t LogLevel
5454
}
5555

56-
var consoleChSize = 256
57-
5856
type LogFn func(string, ...any)
5957
type LogFn2 func(int, string, ...any)
6058

intra/log/logger.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type simpleLogger struct {
8787
// a clock-like spam rate limiter
8888
// maps level+pc to its age in ticks
8989
type clock struct {
90+
sync.Mutex
9091
l2 [NONE + 1][pcbuckets]uint8 // level+pc clock
9192
l1 [NONE + 1]uint8 // level clock
9293
}
@@ -120,7 +121,10 @@ var _ Logger = (*simpleLogger)(nil)
120121
// const logcatLineSize = 1024
121122

122123
// qSize is the number of recent log msgs to keep in the ring buffer.
123-
const qSize = 128
124+
const qSize = 256
125+
126+
// consoleChSize is the size of the console channel.
127+
const consoleChSize = 256
124128

125129
// similarTraceThreshold is the no. of similar stacktraces to report before suppressing.
126130
const similarTraceThreshold = 8
@@ -388,7 +392,7 @@ func (l *simpleLogger) err(at int, msg string) {
388392
}
389393

390394
func caller(at int) (pc uintptr, who string) {
391-
pc, file, line, _ := runtime.Caller(at + 1)
395+
pc, file, line, _ := runtime.Caller(at)
392396
if len(file) <= 0 {
393397
file = "???"
394398
} else {
@@ -437,6 +441,10 @@ func (l *simpleLogger) writelog(lvl LogLevel, at int, msg string, args ...any) {
437441
// not thread-safe for performance reasons
438442
// go.dev/play/p/6CkoACJ1bYz
439443
func (l *simpleLogger) spammy(lvl LogLevel, pc uintptr) (y bool) {
444+
// expensive, but golog's internal logger also grabs a mutex before every write
445+
l.clock.Lock()
446+
defer l.clock.Unlock()
447+
440448
l.clock.l1[lvl]++ // tick the level clock
441449
t := l.clock.l1[lvl]
442450

0 commit comments

Comments
 (0)