Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Please choose versions by [Semantic Versioning](http://semver.org/).
* MINOR version when you add functionality in a backwards-compatible manner, and
* PATCH version when you make backwards-compatible bug fixes.

## Unreleased

- fix: `memoryMonitor.LogMemoryUsage`, `logLevelSetter.Set` and `logLevelSetter.resetLogLevel` now use `libtime` instead of stdlib `time`, matching the convention `log_sampler-time.go` already documents ("uses github.com/bborbe/time for consistent time handling across the library"). All three drive time-threshold logic — log-if-interval-elapsed and auto-reset-after-duration — which could not be exercised deterministically against a frozen clock. The reset check uses `libtime.Now().Sub(lastSetTime)` rather than `time.Since(lastSetTime)`, so both the write and the read of `lastSetTime` come from the same clock.

## v1.6.20

- update Go to 1.26.5 and update dependencies
Expand Down
3 changes: 2 additions & 1 deletion log_memory-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"time"

libtime "github.com/bborbe/time"
"github.com/golang/glog"
)

Expand Down Expand Up @@ -43,7 +44,7 @@ func (m *memoryMonitor) LogMemoryUsage(name string) {
m.mutex.Lock()
defer m.mutex.Unlock()

now := time.Now()
now := libtime.Now()

// Check if enough time has passed since last log
if m.lastLogTime.IsZero() || now.Sub(m.lastLogTime) >= m.logInterval {
Expand Down
5 changes: 3 additions & 2 deletions log_set-loglevel-setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

libtime "github.com/bborbe/time"
"github.com/golang/glog"
)

Expand Down Expand Up @@ -69,7 +70,7 @@ func (l *logLevelSetter) Set(ctx context.Context, logLevel glog.Level) error {
l.mux.Lock()
defer l.mux.Unlock()

l.lastSetTime = time.Now()
l.lastSetTime = libtime.Now()
l.currentLogLevel = logLevel

_ = flag.Set("v", strconv.Itoa(int(logLevel)))
Expand All @@ -90,7 +91,7 @@ func (l *logLevelSetter) resetLogLevel() {
l.mux.Lock()
defer l.mux.Unlock()

if time.Since(l.lastSetTime) <= l.autoResetDuration {
if libtime.Now().Sub(l.lastSetTime) <= l.autoResetDuration {
glog.V(l.defaultLoglevel).Infof("time since lastSet is too short => skip reset loglevel")
return
}
Expand Down