Skip to content

Commit

Permalink
don't skip log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamza15 committed Jan 27, 2025
1 parent 9b1f5c0 commit fa6a42e
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions go/vt/logutil/throttled.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,32 @@ var (
)

func (tl *ThrottledLogger) log(logF logFunc, format string, v ...any) {
now := time.Now()
// now := time.Now()

tl.mu.Lock()
defer tl.mu.Unlock()
logWaitTime := tl.maxInterval - (now.Sub(tl.lastlogTime))
if logWaitTime < 0 {
tl.lastlogTime = now
logF(2, fmt.Sprintf(tl.name+": "+format, v...))
return
}
// If this is the first message to be skipped, start a goroutine
// to log and reset skippedCount
if tl.skippedCount == 0 {
go func(d time.Duration) {
<-time.After(d)
tl.mu.Lock()
defer tl.mu.Unlock()
// Because of the go func(), we lose the stack trace,
// so we just use the current line for this.
logF(0, fmt.Sprintf("%v: skipped %v log messages", tl.name, tl.skippedCount))
tl.skippedCount = 0
}(logWaitTime)
}
tl.skippedCount++
// logWaitTime := tl.maxInterval - (now.Sub(tl.lastlogTime))
// if logWaitTime < 0 {
// tl.lastlogTime = now
logF(2, fmt.Sprintf(tl.name+": "+format, v...))
// return
// }
// // If this is the first message to be skipped, start a goroutine
// // to log and reset skippedCount
//
// if tl.skippedCount == 0 {
// go func(d time.Duration) {
// <-time.After(d)
// tl.mu.Lock()
// defer tl.mu.Unlock()
// // Because of the go func(), we lose the stack trace,
// // so we just use the current line for this.
// logF(0, fmt.Sprintf("%v: skipped %v log messages", tl.name, tl.skippedCount))
// tl.skippedCount = 0
// }(logWaitTime)
// }
//
// tl.skippedCount++
}

// Infof logs an info if not throttled.
Expand Down

0 comments on commit fa6a42e

Please sign in to comment.